简体   繁体   中英

UIBarbuttonItem change the textColor

I have these two buttons in a toolBar and wants to change the color of UIBarButtons how can i do such a thing? i've tried setTitleTextAttributes, but it does not seem like it has a object with that? How can i do this

UIBarButtonItem *sysDoneButton = [self createButtonWithType:UIBarButtonSystemItemDone target:self
                                                         action:@selector(actionPickerDone:)];

UIBarButtonItem *sysCancelButton = [self createButtonWithType:UIBarButtonSystemItemCancel target:self
                                                           action:@selector(actionPickerCancel:)];

A UIBarButtonItem's color is its tintColor . (Or it can use the tintColor inherited from the toolbar you put it into.)

It seems UIBarButtonItems won't change it's tint color once they are added to the navigation bar.

What I did was to create a new one instead with new attributes.

let rightBarButtonItem = UIBarButtonItem(title: "Title", style: .plain, target: self, action: #selector(someAction))
rightBarButtonItem.tintColor = UIColor.white
navigationItem.rightBarButtonItem = rightBarButtonItem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM