在添加到导航控制器的BarButtonItem的快速Xcode项目中,我很难更改字体。我可以在没有问题的情况下改变按钮的颜色,但是字体不会改变。代码:
var navTextColor = UIColor(red:0.3, green:0.09, blue:0.05, alpha:1.0)
self.navigationController?.navigationBar.tintColor = navTextColor发布于 2014-12-19 17:24:02
如果您创建和输出(例如@IBOutlet var barButton: UIBarButtonItem!)链接到您的UIBarButtonItem,您应该能够更改您的字体类型使用setTitleTextAttributes的出口。
barButton.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "Arial", size: 12)!], forState: UIControlState.Normal)Swift3
barButton.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "Arial", size: 12)!], for: UIControlState.normal)发布于 2017-03-12 11:58:47
Swift 3
更改所有TabBarItem字体的另一个简单方法是在ViewDidLoad() of UITabBarController中使用以下代码:(不需要创建一个出口)
UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: "IranSansMobile", size: 15)!], for: UIControlState.normal)发布于 2020-10-05 22:54:33
Swift 5
barButton.setTitleTextAttributes([ NSAttributedString.Key.font: UIFont(name: "Arial", size: 12)!], for: UIControl.State.normal)https://stackoverflow.com/questions/27570826
复制相似问题