我希望成为button.selected
button.backgroundColor = [UIColor whiteColor];
代替黑色
- (void)viewDidLoad {
UINavigationBar * navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 44)];
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeSystem];
[rightButton setTitle:@"save" forState:UIControlStateNormal];
[rightButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[rightButton setBackgroundColor:[UIColor whiteColor]];
[rightButton addTarget:self action:@selector(savetBtn:) forControlEvents:UIControlEventTouchUpInside];
UINavigationItem *navItem = [[UINavigationItem alloc] init];
UIBarButtonItem * buttonOfRight = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
[navItem setRightBarButtonItem :buttonOfRight animated:false];
[navBar pushNavigationItem:navItem animated:false];
[self.view addSubview:navBar];
}
-(void)savetBtn:(UIButton*)button{
button.selected =! button.selected;
if (button.selected) {
[button setTitle:@"edit" forState:UIControlStateNormal];
button.backgroundColor = [UIColor whiteColor];
}else{
[button setTitle:@"save" forState:UIControlStateNormal];
button.backgroundColor = [UIColor whiteColor];
}
}
点击按钮后,背景颜色为黑色,希望是白色