22

Prior to iOS 11, the UINavigationBar buttons and title are being displayed correctly.

Yesterday I downloaded Xcode 9 with iOS 11 and, after building and running without doing changes, both navigation buttons and the title are not being displayed anymore. It shows the UINavigationBar with the correct color I am setting but nothing else.

I tried on different simulators and also I updated an iPhone 7 to iOS 11 beta 5 and the result is the same. Nothing being displayed.

Has someone faced the same problem? I have tried changing different parts of the code and storyboard but nothing affects...

EDIT with screenshots: https://i.stack.imgur.com/oVPB3.jpg

Thanks in advance!

Leeroy Jenkins
  • 253
  • 2
  • 6
  • is this possible to attach your project or code or screen shot or else – Anbu.Karthik Aug 18 '17 at 07:54
  • @Anbu.Karthik I have uploaded a couple of screenshots of what is happening as the project is private. Here they go: http://imgur.com/a/Hy46c – Leeroy Jenkins Aug 18 '17 at 08:27
  • `navigationbar.prefersLargeTitles=NO;` OR `navigationbar.prefersLargeTitles=YES;` as per requirement will do the trick. – Ronak Chaniyara Aug 18 '17 at 09:03
  • @RonakChaniyara I already tried that with no success... – Leeroy Jenkins Aug 18 '17 at 09:08
  • try by adding width constraint for this image-button. – Ronak Chaniyara Aug 18 '17 at 09:10
  • @RonakChaniyara width constraints? This is a `UIBarButtonItem`, it is not a custom view placed there using constraints... But that is not the only problem. Title, the most simple thing in the world, is not showing neither... I am sure that fixing title will fix everything else. – Leeroy Jenkins Aug 18 '17 at 09:35
  • Could this be an iOS11 bug? My search bar now has white text on a white background (making it very hard to read). It was the correct gray before. I manually forced the search bar's text to UIColor.darkTextColor, but that should not be necessary. My problem may be related to what you are seeing. – Jim Leask Sep 07 '17 at 17:30
  • I have the same issue with the Xcode 9 simulator. Everything shows up fine for builds I push out through test flight to an actual iOS 11 device. – Justin Vallely Sep 13 '17 at 16:49
  • @LeeroyJenkinscan you post some of the code you use for setting the nav bar? – Boaz Frenkel Sep 19 '17 at 12:24
  • 2
    More info: This appears to be an Xcode 9 thing, not iOS 11. We've built our iOS 11 release from both Xcode 8 and Xcode 9 to an iOS 11 device. Only the Xcode 9 build had the issue. – Justin Vallely Sep 19 '17 at 19:24
  • @LeeroyJenkins , I am facing same issue, Have you found any solution of this issue? – jigs Nov 03 '17 at 07:13
  • don't you play games with `- (UITraitCollection *)traitCollection` ? – dollar2048 Nov 09 '17 at 15:05
  • 1
    these ios11 navigation bar bugs are so annoying. i want to destroy something. – dy_ Nov 29 '17 at 00:45
  • Any progress? Same problem. – Andrey Oshev Dec 01 '17 at 20:23

11 Answers11

3

For Xcode 9, it appears that it is no longer enough to just set the frame of a custom view that is being injected into the navigationItem titleView. The intrinsic content size of your titleView now must be overriden and set as well.

Here's the code, adjust the width and height to suit your needs:

class NavigationBarTitleView: UIView {

    override var intrinsicContentSize: CGSize {
        return CGSize(width: bounds.width - 100, height: 50)
    }

    ...

}
Justin Vallely
  • 5,932
  • 3
  • 30
  • 44
2

use sizeToFit()! ios 11 automatically sizes it, but ios 10 does not

1

I had the same issue and for me it was caused by subclassing UITabBarController

massimobio
  • 808
  • 9
  • 11
  • I also subclas UITabBarController, too. I'm facing issue with image and title in UITabar, the text overrides the image – Tran Trung Hieu Sep 25 '17 at 09:46
  • 1
    And the specifically cause is that I used this for maintain the old iOS style for tab bar: - (UITraitCollection *)traitCollection { return [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact]; } – Daniele Ceglia Mar 20 '18 at 16:03
1

Did you set "window,rootViewController = ..." in your code ? Try remove it can fix your problem

Phong Cao
  • 21
  • 2
1

I had the same problem in my project where the titles were missing from the navigation bars after updating to Xcode 9 and iOS 11. I solved it by going to the navigation bar of my navigation controller on the storyboard, keeping the Prefers Large Titles unchecked and changing the Title Font under Title Text attributes, which was set by default in Xcode 9 to System 0 to some other option like Caption 1 or Headline. I also changed its children viewcontrollers' navigation bar settings For Large Title to Never instead of Automatic or Always.

rtamesis
  • 11
  • 2
1

I found this code in some inherited codebase, commented it out and everything worked as it did before iOS 11.x.

if (appDelegate.window.rootViewController != self) {
    appDelegate.window.rootViewController = self;
}
Shawn
  • 416
  • 5
  • 18
0

Try to use:

        UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]

or without appearance proxy setting directly to the current navigationBar...It solves my problem, should Apple changed titleText to clear as default in iOS11...?

Also use this if you want the same look as iOS 10:

        if #available(iOS 11, *) {
        nav.navigationBar.prefersLargeTitles = false
    }
jerrygdm
  • 450
  • 1
  • 7
  • 22
  • thanks for the answer but it is not working... Before doing the change you say, `titleTextAttributes` of `UINavigationBar` are `NSColor` and `TextColor` set to `UIExtendedGrayColorSpace 1 1`. After adding the `NSForegroundColorAttributeName` there is only the attribute `NSColor` with the same value as before... – Leeroy Jenkins Aug 23 '17 at 07:23
  • After doing some research, `UIExtendedGrayColorSpace 1 1` is equal to `white`, so it is already correct the color... – Leeroy Jenkins Aug 23 '17 at 07:46
0

Had the same issue with the navigationButton not displayed. I solved it by setting the renderingMode to .alwaysOriginal. (I didn't use templates)

Swift 3 code:

var img =R.image.smt()?.withRenderingMode(.alwaysOriginal)
pereckeSokSzam
  • 111
  • 1
  • 5
0

I had that same issue and none of the above fixed. Although, @Justin Vallely lead to me fix it.

All I did was to set a width on the titleView and everything worked just fine!

EDIT:

Every UIViewController has a navigationItem property, and every navigationItem has an optional titleView.

For reference: https://developer.apple.com/documentation/uikit/uinavigationitem/1624935-titleview

In my case, I was using a custom titleView and I think that's the cause of the problem, since Apple changed the API to support the new navigation bar layout.

Rafael Machado
  • 655
  • 6
  • 12
  • What titleView? – zulkarnain shah Oct 12 '17 at 05:41
  • The one on the view controller (`UIViewController.navigationItem.titleView`) – Rafael Machado Oct 12 '17 at 15:29
  • Setting a width on titleView did not solve my problem. I have even tried intrinsicContentSize with no success. – Bharat Raichur Oct 13 '17 at 01:57
  • Could you provide more context? – Rafael Machado Oct 13 '17 at 22:41
  • I have view controllers added to Navigation controller. Title and bar buttons are working fine with iOS 10 and not working with iOS 11. There is nothing special as to how the title and bar buttons are added to navigation controller. – Bharat Raichur Oct 14 '17 at 14:39
  • Do you have anything custom regrading navigation bar? In my case I had and it was the root of the problem – Rafael Machado Oct 15 '17 at 01:53
  • When I debug the view hierarchy, I get these warnings: AMBIGUOUS LAYOUT for UINavigationBar, can it be the cause for navigation bar being blank? Should I set translatesAutoresizingMaskIntoConstraints to NO, somewhere? I don't see the warnings when I run it on iOS 10. I am unsure where I have to set "translatesAutoresizingMaskIntoConstraints" if I have to. Any information would be helpful. Thank you. – Bharat Raichur Oct 16 '17 at 03:42
  • You can give it a try, for sure...and make sure that you have valid constraints (since it looks like you are using it) – Rafael Machado Oct 16 '17 at 15:14
  • 1
    Ok, I fixed my issue, I have tab bar and Navigation bar and my tab bar buttons were overlapping with the new style for tab bar items. So I had added a trait collection class as mentioned in this: https://stackoverflow.com/questions/44822558/ios-11-uitabbar-uitabbaritem-positioning-issue. I did not realise, it broke my Navigation bar and now I used a slightly different solution mentioned in the same post and everything works fine. – Bharat Raichur Oct 17 '17 at 11:14
  • @BharatRaichur thank you, man. It solved my issue too. Weird! – Andrey Oshev Dec 01 '17 at 20:29
0

Based on the Justin Vallely's comment I've reworked the code a little to ensure proper sizing of the view:

class NavigationBarTitleView: UIView {
    private var width: CGFloat = 0.0
    private var height: CGFloat = 0.0

    override init(frame: CGRect) {
        super.init(frame: frame)
        width = frame.width
        height = frame.height
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override var intrinsicContentSize: CGSize {
        return CGSize(width: width, height: height)
    }
}

In my particular case I've used this view as a container to UISearchBar and now it is well sized and worked perfectly with Swift 4 & iOS 11, just as it used to work on previous iOS & Swift versions

Alexander Telegin
  • 665
  • 1
  • 7
  • 22
0

We were facing the same issue where the navigation bar color is there but the title and the buttons are not showing up. We have double checked the bar was there by triggering a navigation bar background color change 2 seconds after the navigation controller showed up on the screen, so we know the navigation bar was there and we were adding buttons to the correct instance. Same as the OP, this issue only appears on iOS 11 and not iOS 10, and we are using Swift 3.2 running Xcode 9.1.

After hours of fiddling around, it turns out that presenting a navigation controller, then making it as the UIApplication.shared.delegate.window.rootViewController (after the present animation) caused the issue in our case.

If you just skip the present view controller and make the navigation controller as the root view controller, then everything works fine. Of course, you lose the present animation in the case.

Casey
  • 116
  • 3