Change UIBarButtonItem Width

How to change the width of a UIBarButtonItem to 29px? The width of the property does not work, and I do not want to create a UIButton and use initWithCustomView , because I want the square background to adjust to the color of the navigation bar. I am using initWithImage to initialize a UIBarButtonItem .

Here is my button with a current width of 37 pixels. I want to install 29px.

UIButton

+8
ios objective-c width uibarbuttonitem
source share
2 answers

you can not. If you need custom width you will need to use initWithCustomView

+16
source share

You can do this by dropping the image to the panel element using the interface constructor and changing the width of the user view using this code:

 CGRect frame = self.navigationItem.leftBarButtonItem.customView.frame; frame.size.width = 141; self.navigationItem.leftBarButtonItem.customView.frame = frame; 
+6
source share

All Articles