Я хочу, чтобы моя пользовательская кнопка имела белый цвет фона вместо черного на панели навигации - PullRequest
0 голосов
/ 27 апреля 2019

Я надеюсь быть 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];
    }


}

После нажатия кнопки цвет фона черный, я надеюсь, он белый

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...