更改UITabBar徽章字体

更改UITabBar徽章字体

This question already has answers here:
Swift - How to change UITabBarItem badge font?
                                
                                    (4个答案)
                                
                        
                                在11个月前关闭。
            
                    
我尝试像这样更改UITabBar徽章字体:

cartTab = tabBar.items![2]
let font =  UIFont(name: "MyFontName", size: 11)!
cartTab?.setBadgeTextAttributes([NSAttributedStringKey.font.rawValue: font], for: .normal)
cartTab?.setBadgeTextAttributes([NSAttributedStringKey.font.rawValue: font], for: .selected).


我在自定义标签栏控制器(viewDidLoad)中设置此代码。

最佳答案

AppDelegate中尝试此操作(快速3)

let font =  UIFont(name: "MyFontName", size: 11)!
UITabBarItem.appearance().setBadgeTextAttributes([NSFontAttributeName: font], for: .normal)
UITabBarItem.appearance().setBadgeTextAttributes([NSFontAttributeName: font], for: .selected)




更新:

迅捷4

let font =  UIFont(name: "MyFontName", size: 11)!
UITabBarItem.appearance().setBadgeTextAttributes([NSAttributedString.Key.font: font], for: .normal)
UITabBarItem.appearance().setBadgeTextAttributes([NSAttributedString.Key.font: font], for: .selected)

关于ios - 为什么不能更改UITabBar徽章字体iOS Swift? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55085781/

10-10 21:13