ios – 在swift中更改titleTextAttribute

ios – 在swift中更改titleTextAttribute,第1张

概述自从我更新 xcode以来,我似乎无法改变titleTextAttribute.现在当我使用以下代码我得到这个错误: could not find an overload init that accepts this supplied arguments appDelegate中的代码: UINavigationBar.appearance().titleTextAttributes = [NSF 自从我更新 xcode以来,我似乎无法改变TitleTextAttribute.现在当我使用以下代码我得到这个错误:

Could not find an overload init that accepts this supplIEd arguments

appDelegate中的代码:

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)
总结

以上是内存溢出为你收集整理的ios – 在swift中更改titleTextAttribute全部内容,希望文章能够帮你解决ios – 在swift中更改titleTextAttribute所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1095341.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存