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

NavigationBar bar, tint, and title text color in iOS 8

In AppDelegate.swift, in application(_:didFinishLaunchingWithOptions:) I put the following: UINavigationBar.appearance().barTintColor = UIColor(red: 234.0/255.0, green: 46.0/255.0, blue: 73.0/255.0, alpha: 1.0) UINavigationBar.appearance().tintColor = UIColor.white UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white] (For Swift 4 or earlier use NSAttributedStringKey instead of NSAttributedString.Key) For titleTextAttributes, the docs say: You can specify the font, text color, text shadow color, and text shadow offset … 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

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

How to prevent status bar from overlapping content with hidesBarsOnSwipe set on UINavigationController?

Actually it is pretty easy to do. You just need to connect navigation isNavigationBarHidden property with status bar. Objective-C – (BOOL)prefersStatusBarHidden { return self.navigationController.isNavigationBarHidden; } Swift <= 2.3 override func prefersStatusBarHidden() -> Bool { return navigationController?.navigationBarHidden ?? false } Swift 3.0 override var prefersStatusBarHidden: Bool { return navigationController?.isNavigationBarHidden ?? false } And be sure you … Read more

how to hide navigationbar when i push from navigation controller?

Put this code in the view controller you want to hide the navigation bar for. – (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:animated]; } And you may also want to stick this in there, depending on your needs: – (void) viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.navigationController setNavigationBarHidden:NO animated:animated]; }

Is there a way to change the height of a UINavigationBar in Storyboard without using a UINavigationController?

You can set the property barPosition to UIBarPositionTopAttached another way! Add a delegate to your UINavigationBar. Implement -positionForBar: in the delegate class: – (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { return UIBarPositionTopAttached; } Your navigation bar’s top must also be anchored to the Top Layout Guide.

presenting ViewController with NavigationViewController swift

Calling presentViewController presents the view controller modally, outside the existing navigation stack; it is not contained by your UINavigationController or any other. If you want your new view controller to have a navigation bar, you have two main options: Option 1. Push the new view controller onto your existing navigation stack, rather than presenting it … Read more