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

iPhone: Setting Navigation Bar Title

The view controller must be a child of some UINavigationController for the .title property to take effect. If the UINavigationBar is simply a view, you need to push a navigation item containing the title, or modify the last navigation item: UINavigationItem* item = [[UINavigationItem alloc] initWithTitle:@”title text”]; … [bar pushNavigationItem:item animated:YES]; [item release]; or bar.topItem.title … Read more

How to set back button text in iOS navigation controller?

The back button belongs to the previous view controller, not the one currently presented on screen. To modify the back button you should update it before pushing, on the view controller that initiated the segue: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let backItem = UIBarButtonItem() backItem.title = “Something Else” navigationItem.backBarButtonItem = backItem // This … Read more

Adding back button to navigation bar

If you’re using a navigation controller: MyViewController *_myViewController = [[MyViewController alloc] initWithNibName:@”MyViewController” bundle:nil]; [[self navigationController] pushViewController:_myViewController animated:YES]; UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:@”Back” style:UIBarButtonItemStyleDone target:nil action:nil]; self.navigationItem.backBarButtonItem = _backButton; [_backButton release], _backButton = nil; [_myViewController release], _myViewController = nil; If you’re not using a navigation controller, look into the Three20 style components to make custom … Read more

UINavigationBar multi-line title

Set the titleView property of the UINavigationItem. For example, in the view controller’s viewDidLoad method you could do something like: UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 44)]; label.backgroundColor = [UIColor clearColor]; label.numberOfLines = 2; label.font = [UIFont boldSystemFontOfSize: 14.0f]; label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5]; label.textAlignment = UITextAlignmentCenter; label.textColor = [UIColor whiteColor]; label.text = … 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];

Can’t assign multiple Buttons to UINavigationItem when using Storyboard with iOS 5

I found an easy solution. 1) Add the folowing category: @interface UINavigationItem(MultipleButtonsAddition) @property (nonatomic, strong) IBOutletCollection(UIBarButtonItem) NSArray* rightBarButtonItemsCollection; @property (nonatomic, strong) IBOutletCollection(UIBarButtonItem) NSArray* leftBarButtonItemsCollection; @end @implementation UINavigationItem(MultipleButtonsAddition) – (void) setRightBarButtonItemsCollection:(NSArray *)rightBarButtonItemsCollection { self.rightBarButtonItems = [rightBarButtonItemsCollection sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@”tag” ascending:YES]]]; } – (void) setLeftBarButtonItemsCollection:(NSArray *)leftBarButtonItemsCollection { self.leftBarButtonItems = [leftBarButtonItemsCollection sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@”tag” ascending:YES]]]; } – (NSArray*) rightBarButtonItemsCollection { … Read more

How to enable back/left swipe gesture in UINavigationController after setting leftBarButtonItem?

You need to handle two scenarios: When you’re pushing a new view onto the stack When you’re showing the root view controller If you just need a base class you can use, here’s a Swift 3 version: import UIKit final class SwipeNavigationController: UINavigationController { // MARK: – Lifecycle override init(rootViewController: UIViewController) { super.init(rootViewController: rootViewController) delegate … Read more

How to change the UINavigationController back button name?

If you wish to do this programmatically, it can be done like this: Objective-C UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@”Custom” style:UIBarButtonItemStyleBordered target:nil action:nil]; [self.navigationItem setBackBarButtonItem:backItem]; Swift let backItem = UIBarButtonItem(title: “Custom”, style: .Bordered, target: nil, action: nil) navigationItem.backBarButtonItem = backItem However, if you prefer using Interface Builder, just select the UINavigationItem that you wish to … Read more