Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set UIBarButton size in iOS 11 to match size in iOS 10 [closed]

Tags:

ios

iphone

ios11

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.

like image 990
Kevin Stewart Avatar asked Aug 18 '17 14:08

Kevin Stewart


1 Answers

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.

like image 195
matt Avatar answered Oct 16 '22 15:10

matt