我在工具栏中添加了一个自定义按钮并设置了属性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];
}
答案 0 :(得分:0)
您忘记为禁用状态设置背景图片...
[ pTestBtn setBackgroundImage: **imageDisabled** forState: UIControlStateDisabled ];