Get the frame of UIBarButtonItem in Swift?

You should try it like: var barButtonItem = self.navigationItem.rightBarButtonItem! var buttonItemView = barButtonItem.valueForKey(“view”) var buttonItemSize = buttonItemView?.size Edit (Swift 3): var barButtonItem = self.navigationItem.rightBarButtonItem! let buttonItemView = barButtonItem.value(forKey: “view”) as? UIView var buttonItemSize = buttonItemView?.size

How to tint UIBarButtonItem background color? [duplicate]

I found this solution preferable to those listed here: Tint UIButton and UIBarButtonItem. Unlike the accepted answer, it allows you to change the color of UIBarButtonItems independent of the UINavigationBar. In case the link goes down in the future, the gist of it is that you create a tinted UISegmentedControl (with UISegmentedControlStyleBar) with one segment, … Read more

setting image for UIBarButtonItem – image stretched

The best way to do this is to create a button, set its background image, and set its action. Then a UIBarButtonItem can be created using this button as the custom view. Here’s my example code: UIButton *settingsView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 61, 30)]; [settingsView addTarget:self action:@selector(SettingsClicked) forControlEvents:UIControlEventTouchUpInside]; [settingsView setBackgroundImage:[UIImage imageNamed:@”settings”] forState:UIControlStateNormal]; UIBarButtonItem *settingsButton … Read more

Xcode 6 Storyboard Unwind Segue with Swift Not Connecting to Exit

This is a known issue with Xcode 6: Unwind segue actions declared in Swift classes are not recognized by Interface Builder In order to get around it you need to: Change class MyViewController to @objc(MyViewController) class MyViewController Create an Objective-C header file with a category for MyViewController that redeclares the segue action. @interface MyViewController (Workaround) … Read more

QLPreviewController remove or add UIBarButtonItems

I searched for a solution to this problem for months and finally found a way to customize the navigationbar of a QLPreviewController. Previously I was also using UIWebView to display documents as I’m not allowed to display the iOS-share button for certain confidential documents within my app and this is what the QLPreviewController does. However … Read more

UIBarButtonItem with custom view not properly aligned on iOS 7 when used as left or right navigation bar items

Works until iOS11! You can use negative flexible spaces and rightBarButtonItems property instead of rightBarButtonItem: UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; spacer.width = -10; // for example shift right bar button to the right self.navigationItem.rightBarButtonItems = @[spacer, yourBarButton];