如何将导航栏中创建的按钮设置为iPhone中的自定义按钮?
我是 iphone 开发的新手。我在导航栏上创建了一个 UIBarButtonItem。我想将其设置为自定义。 “style:”属性没有自定义属性。请帮助我。谢谢。
leftbutton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"LEFT.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftbutton)];
self.navigationItem.leftBarButtonItem = leftbutton;
[self.navigationItem]
[leftbutton release];
I am new to iphone development.I have created a UIBarButtonItem on the navigation bar.I want to set the proper to custom. There is no property as custom for "style:" attribute.Please help me out.Thanks.
leftbutton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"LEFT.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftbutton)];
self.navigationItem.leftBarButtonItem = leftbutton;
[self.navigationItem]
[leftbutton release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只想在 Apple 的常用按钮框架内显示 .png 文件,那么您的代码就可以。如果您的 png 文件未显示,只需检查它是否有效。
如果您想制作自己的按钮,可以使用
-(id)initWithCustomView:(UIView *)customView
查看这篇文章以获取有趣的示例代码:
自定义栏按钮示例代码
If you just want to display a .png file inside the usual button frame from Apple, then your code is ok. If your png file is not displaying, just check if it's valid.
If you want to make your own button, you can use
-(id)initWithCustomView:(UIView *)customView
Check this post for an interesting sample code :
Custom Bar Button Sample Code
您可以使用
- (id)initWithCustomView:(UIView *)customView
方法使用您想要的任何自定义视图创建项目。You can create item with
- (id)initWithCustomView:(UIView *)customView
method with whatever custom view you want.UIBarButtonItem 有 4 个初始值设定项,涵盖了您所需要的所有内容:
style 属性仅对标准按钮有意义。
UIBarButtonItem has 4 initializers which cover all you will ever need:
The style property makes sense only for standard buttons.