Change the width of an UIBarButtonItem [duplicate]
Asked Answered
E

2

8

How can I change the width of an UIBarButtonItem to 29px? The property width does not work and I don't want to create a UIButton and use the initWithCustomView because I want the square background to adjust to the navigation bar color. I'm using the initWithImage to init the UIBarButtonItem.

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

UIButton

Encroachment answered 27/12, 2011 at 10:17 Comment(1)
@MaxMacLeod The asker specifically doesn't want to use initWithCustomView...Parkman
T
16

you cant. If you want custom width you will need to use initWithCustomView

Trickle answered 28/12, 2011 at 9:25 Comment(2)
But why do they have the property width in the UIBarButtonItem class?Encroachment
you can use it only if button in UIToolbarTrickle
G
5

You can do it by dropping an image to the bar button item from the interface builder and changing the width of the custom view with this code:

CGRect frame = self.navigationItem.leftBarButtonItem.customView.frame;
frame.size.width = 141;
self.navigationItem.leftBarButtonItem.customView.frame = frame;
Godart answered 11/1, 2013 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.