11

I have an view controller with a simple UINavigationBar with a rightBarButtonItem which contains a button view with an image asset.

In iOS 10, this UIBarButtonItem would be sized properly, not filling up the entire height and of the navigation bar and therefore taking up enough width to stay proportional to the height. Similar to how UIBarButton items look in Apple's app throughout iOS.

Now in iOS 11, these icons are massive and take up way more space than they used to in iOS 10.

Is there a way to restore them to how they looked on iOS 10? I tried adding constraints to the customView property of the UIBarButtonItems to no avail.

Kevin Stewart
  • 415
  • 6
  • 16
  • 1
    What's a "button view with an image asset"? Show your code! Adding constraints _is right_; what constraints did you add? – matt Aug 18 '17 at 15:54

1 Answers1

3

Your approach is correct: custom bar button items now do autolayout, so you must add constraints to set the size. This is a much-requested feature, so don't worry, be happy!

The constraints you must add are like the constraints for a table cell height: you must add sufficient constraints to size the bar button item's custom view completely from the inside out. For example, give it absolute width and height constraints, or give its contents width and height constraints plus constraints pinning them to the boundaries of the custom view itself.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    This worked for me. Turns out I needed to add width and height constraints to the customView property. Thanks! – Kevin Stewart Aug 18 '17 at 19:25
  • 3
    @KevinStewart I have the same problem. It is not clear what the constraints I need are. Since I already create a frame for the button, I’m guessing it is some kind of pinning constraints. Could you post your code? – JScarry Sep 15 '17 at 18:30
  • 2
    I can post an example of how I fixed it if this question was unlocked along with a reusable way to do it. No idea why it's locked as unclear when clearly many people are having this issue. – Kevin Stewart Sep 25 '17 at 14:34
  • @KevinStewart Please post your appropriate solution for custom bar button items – BalKrishan Yadav Nov 16 '17 at 13:36