Swift-如何更改UITabBarItem徽章字体? [英] Swift - How to change UITabBarItem badge font?

查看:180
本文介绍了Swift-如何更改UITabBarItem徽章字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITabBar.我为标签栏项目设置了一个值:

I have a UITabBar. I set a value for tab bar items:

tabBarItem3?.badgeValue = String(self.numberOfProducts)

现在,我想将其字体更改为特定字体.然后我用了这段代码:

Now I want to change its font to a specific font. Then I used this code :

tabBarItem3?.setBadgeTextAttributes([NSFontAttributeName: UIFont(name: "IRANSans", size: 14)], for: .normal)

它不起作用.我该怎么办?

It doesn't work. What should I do?

推荐答案

Swift 3

UITabBarItem.appearance().setBadgeTextAttributes([NSFontAttributeName: UIFont(name: "IRANSans", size: 14)], for: .normal)
UITabBarItem.appearance().setBadgeTextAttributes([NSFontAttributeName: UIFont(name: "IRANSans", size: 14)], for: .selected)

这篇关于Swift-如何更改UITabBarItem徽章字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆