Обновление UIBarButtonItem в контроллере представления - PullRequest
0 голосов
/ 11 июня 2019

Я пытаюсь обновить UIBarButtonItem оттенок цвета из контроллера вида, но ничего не изменилось.Разве мы не можем получить доступ к UIBarButtonItem в контроллере вида, используя self.navigationItem.rightBarButtonItem?

[UIView animateWithDuration:.8 delay:0.5 options:UIViewAnimationOptionAllowUserInteraction animations:^ {
        //button.alpha = .01;  //don't animate alpha to 0, otherwise you won't be able to interact with it
        self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    } completion:^(BOOL finished) {
        self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    }];

Ответы [ 3 ]

0 голосов
/ 11 июня 2019
let addButton = UIButton(type: .custom)
addButton.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
addButton.tintColor = UIColor.gray
let addMoreItem = UIBarButtonItem(customView: addButton)
self.navigationItem.rightBarButtonItem = addMoreItem

это может быть работой для вас.

0 голосов
/ 11 июня 2019
UIButton *btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[btnback setTintColor:[UIColor whiteColor]];
[btnBack addTarget:self action:@selector(onClickBtnBack:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
self.navigationItem.rightBarButtonItem = barButtonItem;

также вы можете установить цвет фона и текста.

0 голосов
/ 11 июня 2019

Я попробовал вашу проблему, сделав розетку UIBarButtonItem.Работает нормально.Вы можете установить оттенок цвета по прямой ссылке.

Вот код

class ViewController: UIViewController {

@IBOutlet weak var addItem: UIBarButtonItem!
var  username = UITextField()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.


}

@IBAction func addItem(_ sender: UIBarButtonItem) {

    UIView.animate(withDuration: 20) {

        self.addItem.tintColor = UIColor.red
    }
}
}
...