gpt4 book ai didi

ios - 快速更改 titleTextAttribute

转载 作者:IT王子 更新时间:2023-10-29 05:10:02 26 4
gpt4 key购买 nike

自从我更新 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, NSForegroundColorAttributeName:UIColor.whiteColor()], forState: UIControlState.Normal)

关于ios - 快速更改 titleTextAttribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26868847/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com