设置NavigationItem的alpha值

时间:2011-08-10 09:02:05

标签: iphone objective-c ios uinavigationitem

我尝试设置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;

1 个答案:

答案 0 :(得分:7)

在您的代码中,您尝试为rightBarButtonItem的alpha设置customView,但您的rightBarButton项目不包含任何自定义视图。不是吗?

UIBarButtonItem item是UIBarItem的直接子类,后者又是NSObject的子类。因此,无法直接设置其alpha。您为alpha设置customView是正确的,但您错过了添加customView本身; - )