UIBarButtonItem is disabled, but has normal color

前端 未结 6 1179
失恋的感觉
失恋的感觉 2021-02-12 19:25

I\'m having an issue with a UIBarButtonItem. I use the appearance proxy to set its color for states Normal and Disabled and I do this in t

6条回答
  •  天涯浪人
    2021-02-12 20:01

    Check with following code.

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        UIBarButtonItem * btnTemp = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(btnDone_Click:)];
        [btnTemp setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor lightGrayColor], NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f]} forState:UIControlStateNormal];
    
        [btnTemp setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blueColor], NSFontAttributeName:[UIFont systemFontOfSize:16.0f]} forState:UIControlStateDisabled];
    
        [self.navigationItem setRightBarButtonItem:btnTemp];
    
    }
    
    - (void)btnDone_Click : (id)sender {
    
        UIBarButtonItem * button = (UIBarButtonItem *)sender;
        [button setEnabled:FALSE];
        [self performSelector:@selector(enableButton:) withObject:sender afterDelay:2.0f];
    
    
    }
    
    - (void)enableButton : (id)sender {
        UIBarButtonItem * button = (UIBarButtonItem *)sender;
        [button setEnabled:TRUE];
    }
    

提交回复
热议问题