最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift中UITabBarItem的字体太小

Swift crifan 4872浏览 0评论

[背景]

代码:

        //create tabs
        let viewMessage         = MessageViewController()
        let viewContact         = ContactViewController()
        let viewFile            = FileViewController()
        let viewPersonalCenter  = PersonalCenterViewController()

        let nvcMessage = UINavigationController(rootViewController: viewMessage)
        nvcMessage.tabBarItem = UITabBarItem(title: mainTabs[0], image: UIImage(named:"message_unselected.png"), tag:0)
        let nvcContact = UINavigationController(rootViewController: viewContact)
        nvcContact.tabBarItem = UITabBarItem(title: mainTabs[1], image: UIImage(named:"contact_unselected.png"), tag:1)
        let nvcFile = UINavigationController(rootViewController: viewFile)
        nvcFile.tabBarItem = UITabBarItem(title: mainTabs[2], image: UIImage(named:"file_unselected.png"), tag:2)
        let nvcPersonalCenter = UINavigationController(rootViewController: viewPersonalCenter)
        nvcPersonalCenter.tabBarItem = UITabBarItem(title: mainTabs[3], image: UIImage(named:"personal_center_unselected.png"), tag:3)



        self.viewControllers = [nvcMessage, nvcContact, nvcFile, nvcPersonalCenter]
        //default select message index 0
        self.selectedIndex = 0

结果使得:

uitabbaritem font size too small

UITabBarItem
中的字体小了。
想要变大点。
 [解决过程]

1.搜:

UITabBarItem font size
参考:
        let barItemFont = UIFont.systemFontOfSize(18)

        let nvcMessage = UINavigationController(rootViewController: viewMessage)
        nvcMessage.tabBarItem = UITabBarItem(title: mainTabs[0], image: UIImage(named:"message_unselected.png"), tag:0)

        nvcMessage.tabBarItem.setTitleTextAttributes([NSFontAttributeName: barItemFont], forState: UIControlState.Normal)
 使的字体变大了:
tab bar item size bigger
[总结]
UITabBarItem的字体默认小,通过:
nvcMessage.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(18)], forState: UIControlState.Normal)

即可使的字体变大些了。

转载请注明:在路上 » [已解决]swift中UITabBarItem的字体太小

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
86 queries in 0.417 seconds, using 22.09MB memory