gpt4 book ai didi

ios - 如何仅更改 UITabBar 项目中的字体大小?

转载 作者:行者123 更新时间:2023-11-28 14:57:12 25 4
gpt4 key购买 nike

如何只改变 UITabBar Item 中的字体大小?

在我的 AppDelegate 中:

这是我加的

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// [START initialize_firebase]
FirebaseApp.configure()
// [END initialize_firebase]
// Override point for customization after application launch.


let selectedAttr = UITabBarItem.appearance().titleTextAttributes(for: UIControlState.selected)
let normalAttr = UITabBarItem.appearance().titleTextAttributes(for: UIControlState.normal)
//
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.font: UIFont(name: normalAttr.fontName, size: 15)!], for: UIControlState.normal)


UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.font: UIFont(name: normalAttr.fontname, size: 15)!], for: UIControlState.selected)

return true
}

但我没有看到任何 normalAttr.fontName 属性。我该如何解决这个问题?

最佳答案

titleTextAttributes(for:) 返回一个字典,您可以使用它来键入查找字体。

    let normalAttr = UITabBarItem.appearance().titleTextAttributes(for: UIControlState.normal)
let font = normalAttr[NSFontAttributeName] as! UIFont // <-- This instance has a property called `fontName`
...
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.font: UIFont(name: font.fontName, size: 15)!], for: UIControlState.normal)

关于ios - 如何仅更改 UITabBar 项目中的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49218250/

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