设置 NavigationItem 的 alpha 值
我尝试设置 navigationItem 的 alpha 值来为 rightBarbutton 设置动画,但我无法更改该值。有什么建议吗?
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"Avbryt"
style:UIBarButtonItemStyleBordered
target:self action:@selector(cancelEditing)] autorelease];
self.navigationItem.rightBarButtonItem.customView.alpha = 0.5;
I try to set the alpha value of a navigationItem to animate the rightBarbutton, but I can´t get it change the value. Any suggestions?
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"Avbryt"
style:UIBarButtonItemStyleBordered
target:self action:@selector(cancelEditing)] autorelease];
self.navigationItem.rightBarButtonItem.customView.alpha = 0.5;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的代码中,您尝试为 rightBarButtonItem 的
customView
设置alpha
,但您的 rightBarButton 项目不包含任何自定义视图。不是吗?UIBarButtonItem
项是UIBarItem
的直接子类,而UIBarItem
又是NSObject
的子类。因此,无法直接设置其alpha
。您对customView
设置alpha
的看法是正确的,但您错过了添加 customView 本身;-)In your code you are trying to set
alpha
for the rightBarButtonItem'scustomView
, but you your rightBarButton item doesn't contain any custom view. Isn't it?UIBarButtonItem
item is a direct subclass ofUIBarItem
which in turn is a subclass ofNSObject
. So, it is not possible to set itsalpha
directly. You are correct about settingalpha
for thecustomView
, but you have missed to add the customView itself ;-)