本文介绍了具有普通样式的UINavigationBar BarButtonItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到了以下代码:
- (id)init {
if (self = [super init]) {
self.title = @"please wait";
UIBarButtonItem *favorite = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"star.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonFavoriteClicked:)];
self.navigationItem.rightBarButtonItem = favorite;
}
return self;
}
但我的按钮看起来仍然像一个带有UIBarButtonItemStyleBordered的按钮
but my button looks still like a Button with UIBarButtonItemStyleBorderedalt text http://img693.imageshack.us/img693/1632/bildschirmfoto20100227ui.png
有没有办法在这个位置设置一个普通风格的按钮?
is there a way to set a button with plain style at this position?
推荐答案
在界面构建器中创建一个UIButton,使其看起来完全符合您的要求。在你的.h中创建一个插座:
Create a UIButton in interface builder, make it look like exactly what you want. Create an outlet for in in your .h:
IBOutlet UIButton * _myButton;
然后使用自定义视图将其设置为右侧栏按钮项,这将消除边框:
Then set it as your right bar button item using a custom view, which will eliminate the border:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_myButton];
这是因为UIButton是UIView的子类。
This works because UIButton is a subclass of UIView.
这篇关于具有普通样式的UINavigationBar BarButtonItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!