Reputation: 1735
I'm trying to make a custom UIBarButtonItem
class to just change the font and the color of the Bar Button I have added to my View controllers. and I have more than 20 Buttons that need to be changed.
How could I do this by just adding a custom UIBarButtonItem
Class from the (Identity Inspector) story board ?
Upvotes: 3
Views: 1189
Reputation: 2740
Create class for UIBarButtonItem
class CustomBarButton: UIBarButtonItem {
override func awakeFromNib() {
style = .plain
tintColor = .red
//Set font name and size
guard let font = UIFont(name: "Helvetica-Bold", size: 19) else {
return
}
setTitleTextAttributes([NSAttributedStringKey.font:font], for: .normal)
}
}
Set CustomBarButton class to UIBarButtonItem from Identity Inspector.
Upvotes: 3