UITabbarItem.appearance().setTitleTextAttributes([NSForegroundcolorAttributename: UIcolor.blackcolor()],forState:.normal)UITabbarItem.appearance().setTitleTextAttributes([NSForegroundcolorAttributename: UIcolor.whitecolor()],forState:.Selected)
但是,如果添加:
UITabbarItem.appearance().setTitleTextAttributes([NSFontAttributename:UIFont(name: "American Typewriter",size: 13)!],forState: .Selected)
由于某种原因,当文本被选中和未被选中时,文本变为黑色,并且字体保持不变.
奇怪的是,如果我更改.在最后一个片段中选择.normal,那么所选文本将变为白色,文本将与代码中的字体匹配.
UITabbarItem.appearance().setTitleTextAttributes([NSFontAttributename:UIFont(name: "American Typewriter",forState: .normal)
这几乎是完美的,但是未选择的文本现在没有变化.我不确定我做错了什么或这是一个错误,但如果有任何其他方法来完成这项任务,我很乐意听到它.
基于dfri的评论,我试过这个:
UITabbarItem.appearance().setTitleTextAttributes([NSForegroundcolorAttributename: UIcolor.blackcolor(),NSFontAttributename : [NSFontAttributename:UIFont(name: "American Typewriter",size: 13)!]],forState:.Selected)UITabbarItem.appearance().setTitleTextAttributes([NSForegroundcolorAttributename : UIcolor.whitecolor(),forState:.normal)
现在应用程序崩溃了.错误说:
unrecognized selector sent to instance 0x7fa6d9461ef0
这对我没有任何意义
解决方法 请尝试以下方法let colornormal : UIcolor = UIcolor.blackcolor()let colorSelected : UIcolor = UIcolor.whitecolor()let TitleFontAll : UIFont = UIFont(name: "American Typewriter",size: 13.0)!let attributesnormal = [ NSForegroundcolorAttributename : colornormal,NSFontAttributename : TitleFontAll]let attributesSelected = [ NSForegroundcolorAttributename : colorSelected,NSFontAttributename : TitleFontAll]UITabbarItem.appearance().setTitleTextAttributes(attributesnormal,forState: .normal)UITabbarItem.appearance().setTitleTextAttributes(attributesSelected,forState: .Selected)总结
以上是内存溢出为你收集整理的自定义文本颜色和UITabBarItem的字体导致怪异导致swift全部内容,希望文章能够帮你解决自定义文本颜色和UITabBarItem的字体导致怪异导致swift所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)