Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize UIBarButtonItem in code

How do I resize a UIBarButtonItem in the code?

like image 919
Jack Humphries Avatar asked Aug 05 '11 00:08

Jack Humphries


2 Answers

Use the UIBarButtonItem's width property to resize the button to fit by setting it to 0.

UIBarButtonItem* btn = // init
btn.width = .0f;

From Apple's docs: "If the value is 0.0 or negative, the item sets the width of the combined image and title to fit" https://developer.apple.com/library/ios/documentation/uikit/reference/UIBarButtonItem_Class/Reference/Reference.html#//apple_ref/occ/instp/UIBarButtonItem/width

like image 79
Carl Avatar answered Oct 20 '22 16:10

Carl


You can't resize a UIBarButtonItem as you would a UIView. What you can do is change its width property.

UIBarButtonItem *b;
// Initialize and such ...
b.width = 150.0;

This should work for a Fixed Space Bar Button Item.

like image 37
fsaint Avatar answered Oct 20 '22 17:10

fsaint