开发者

I want a UINavigationItem to be a square button with an image. How do i do this?

开发者 https://www.devze.com 2023-03-11 05:08 出处:网络
I want to put a square button in the UINavigationBar, much like the + button, but with an image I have. When i do this:

I want to put a square button in the UINavigationBar, much like the + button, but with an image I have. When i do this:

self.navigationIt开发者_运维百科em.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"settings wheel.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(prefsPressed)];

It just stretches the image out and makes a long button. Any ideas how to make it square?


UIBarButtonItem has a width property you can set. I'm not sure if that will do the trick for you, though. If not, you can go with creating a custom UIView (e.g. a UIImageView) and setting it using the initWithCustomView method:

See here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIBarButtonItem_Class/Reference/Reference.html

0

精彩评论

暂无评论...
验证码 换一张
取 消