iPhone SDK:如何将图像添加到UIBarButton? [英] iPhone SDK: How to add an image to a UIBarButton?

查看:50
本文介绍了iPhone SDK:如何将图像添加到UIBarButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用下面的代码在导航栏上创建带有图像的按钮.

I have used the code below to create a button on the nav bar with an image.

我可以看到该图像,但也可以看到其周围的按钮边框.我的问题是,如何摆脱按钮边框.我只想看一下导航栏上的图像,没有边框.

I can see the image but I can also see the border of the button around it. My question is, how can I get rid of the button border. All I want to see is the image on the nav bar, no border.

UIBarButtonItem *settingsBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_prefs.png"] style:UIBarButtonItemStylePlain target:self action:@selector(openSettings:)];
[[self navigationItem] setLeftBarButtonItem:settingsBtn];
[settingsBtn release];

先谢谢了.任何指针,进一步阅读的链接或示例都值得赞赏.

Thanks in advance. Any pointers, links to read further or examples appreciated.

推荐答案

这是我当前项目之一的代码片段.它为UIBarButtonItem:

Here's a code fragment from one of my current projects. It loads an image with transparency for a UIBarButtonItem:

UIImage* image = [UIImage imageNamed:@"some-image.png"];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
UIButton* someButton = [[UIButton alloc] initWithFrame:frame];
[someButton setBackgroundImage:image forState:UIControlStateNormal];
[someButton setShowsTouchWhenHighlighted:YES];
UIBarButtonItem* someBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:someButton];
[self.navigationItem setRightBarButtonItem:someBarButtonItem];
[someBarButtonItem release];
[someButton release];

这篇关于iPhone SDK:如何将图像添加到UIBarButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆