自从我更新
xcode以来,我似乎无法改变titleTextAttribute.现在当我使用以下代码我得到这个错误:
could not find an overload init that accepts this supplied arguments@H_404_4@
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: "Ubuntu",size: 17),NSForegroundColorAttributeName:UIColor.whiteColor()] UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: "Ubuntu-Light",size: 15),NSForegroundColorAttributeName:UIColor.whiteColor()],forState: UIControlState.Normal)
解决方法
最近有一个变化,所以UIFont(name:size :)返回一个可选的UIFont实例.你需要解开它们才能使它工作.使用!是最简单的方法,但如果字体不在系统上,会让您崩溃.尝试像:
let navbarFont = UIFont(name: "Ubuntu",size: 17) ?? UIFont.systemFontOfSize(17) let barbuttonFont = UIFont(name: "Ubuntu-Light",size: 15) ?? UIFont.systemFontOfSize(15) UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: navbarFont,NSForegroundColorAttributeName:UIColor.whiteColor()] UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: barbuttonFont,forState: UIControlState.Normal)