iPhone UIBarButtonItem setCustomView:方法?
我想自定义 UIBarButtonItem 的背景。这是我使用的代码:
UIButton *button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[button setBackgroundImage:[UIImage imageNamed:@"ButtonBackground.png"] forState:UIControlStateNormal];
[editButton setCustomView:button]; // editButton is the UIBarButtonItem
不幸的是,这不起作用。它没有显示 UIBarButtonItem,而是直接消失(变得 100% 透明)。当我省略 setCustomView 方法时,会出现 UIBarButtonItem,但未自定义。
我该如何解决这个问题?
谢谢!
富有的
I want to customize a UIBarButtonItem's background. Here's the code I use:
UIButton *button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[button setBackgroundImage:[UIImage imageNamed:@"ButtonBackground.png"] forState:UIControlStateNormal];
[editButton setCustomView:button]; // editButton is the UIBarButtonItem
Unfortunately, this doesn't work. Instead of showing the UIBarButtonItem, it simply vanishes (it becomes 100% transparent). When I leave out the setCustomView method, the UIBarButtonItem appears, but is not customized.
How can I solve this problem?
Thanks!
Rich
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该尝试将
UIButton
的frame 属性设置为合理的值,例如,如果没有设置框架,则添加UIView 将不会显示。这就是为什么它看起来看不见。它实际上就在那里,只是大小为 0。
You should try to set the
UIButton
's frame property to something reasonable, e.g. add aUIView's will not display if they don't have a frame set. This is why it seems invisible. It's actually there, it just has a size of 0.