1

I have added a custom button to a toolbar and have set the property setEnabled:NO but the button does not shows up greyed out when the view loads using SDK 4.0. However if the same code is compiled with SDK 3.1.2 the button shows up greyed out. Any ideas?

- (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];

}
Robin
  • 10,011
  • 5
  • 49
  • 75
user636060
  • 13
  • 3

1 Answers1

0

You forgot to set the background image for the disabled state...

[ pTestBtn setBackgroundImage: **imageDisabled** forState: UIControlStateDisabled ];
Macmade
  • 52,708
  • 13
  • 106
  • 123
  • Actually i have set the same image for the disabled state but just did not copy that code here. I can put a different image for disabled state but would like to know why is it not working when compiled with SDK 4.0. Any other suggestions please? – user636060 Feb 27 '11 at 18:34