我已将自定义按钮添加到工具栏并设置了属性 setEnabled:NO 但是当使用 SDK 4.0 加载视图时该按钮不会显示为灰色。但是,如果使用 SDK 3.1.2 编译相同的代码,则该按钮显示为灰色。有任何想法吗?
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UIImage* pImage = [UIImage imageNamed:@"Test.png"];
CGRect TestBtnFrame = CGRectMake(0, 0, pImage.size.width, pImage.size.height);
UIButton* pTestBtn = [[UIButton alloc] initWithFrame:TestBtnFrame];
[pTestBtn setTitle:@" Test" forState:UIControlStateNormal];
[pTestBtn addTarget:self action:@selector(OnTestBtnClick) forControlEvents:UIControlEventTouchUpInside];
[pTestBtn setBackgroundImage:image forState:UIControlStateNormal];
// [pTestBtn setEnabled:NO];
// Class member variable to be released in dealloc
m_pTestBarBtn = [[UIBarButtonItem alloc] initWithCustomView: pTestBtn];
[pTestBtn release];
[m_pTestBarBtn setEnabled:NO];
[self setToolbarItems:[NSArray arrayWithObjects: m_pTestBarBtn, nil] animated:YES];
}