作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用下面的代码在导航栏上创建一个带有图像的按钮。
我可以看到图像,但我也可以看到图像周围按钮的边框。我的问题是,如何去掉按钮边框。我只想看到导航栏上的图像,没有边框。
UIBarButtonItem *settingsBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_prefs.png"] style:UIBarButtonItemStylePlain target:self action:@selector(openSettings:)];
[[self navigationItem] setLeftBarButtonItem:settingsBtn];
[settingsBtn release];
提前致谢。任何指针、进一步阅读的链接或示例表示赞赏。
最佳答案
这是我当前项目之一的代码片段。它为 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 : How to add an image to a UIBarButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2924044/
我是一名优秀的程序员,十分优秀!