UIBarbuttonItem change the textColor

纵饮孤独 提交于 2019-12-20 04:24:12

问题


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:)];

回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/26917055/uibarbuttonitem-change-the-textcolor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!