gpt4 book ai didi

ios - 更改所有导航栏中的标题文本颜色和字体

转载 作者:搜寻专家 更新时间:2023-11-01 07:26:53 27 4
gpt4 key购买 nike

我正在使用 swift 2 和最新版本的 Xcode,我正在尝试更改每个导航栏中标题文本的字体大小、名称和颜色。我在 didFinishLaunchingWithOptions 区域的 AppDelegate 部分中编写了以下代码,但它只会更改颜色,不会影响字体的大小或类型。当我去掉颜色线时,标题就在 NSFontAttributeName 行之后。有没有办法让两行代码都执行?我还没有找到任何允许您在代码中更改两者的东西...

   func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.


UIApplication.sharedApplication().statusBarStyle = .LightContent
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: (UIFont(name: "AvenirNext-DemiBold", size: 50.0))!]
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor(red: 244/255, green: 234/255, blue: 166/255, alpha: 1.0)]


return true
}

最佳答案

你的代码很愚蠢。您设置了 titleTextAttributes,然后丢弃您刚设置的值并替换它为另一个值!

UINavigationBar.appearance().titleTextAttributes = 
[NSFontAttributeName: (UIFont(name: "AvenirNext-DemiBold", size: 50.0))!]
UINavigationBar.appearance().titleTextAttributes =
[NSForegroundColorAttributeName : UIColor(red: 244/255, green: 234/255, blue: 166/255, alpha: 1.0)]

如果这不是您想要的,请将 titleTextAttributes 设置为仅一个值,即包含两个设置的字典:

UINavigationBar.appearance().titleTextAttributes = [
NSFontAttributeName: (UIFont(name: "AvenirNext-DemiBold", size: 50.0))!,
NSForegroundColorAttributeName : UIColor(red: 244/255, green: 234/255, blue: 166/255, alpha: 1.0)
]

关于ios - 更改所有导航栏中的标题文本颜色和字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35495713/

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