在 Swift 中更改标签栏字体 [英] Changing tab bar font in Swift

查看:34
本文介绍了在 Swift 中更改标签栏字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试更改标签栏项目的字体,但是我找不到任何 Swift 示例.我知道这就是你在 Objective-C 中改变它的方式:

I have been trying to change the font for the tab bar items however I haven't been able to find any Swift examples. I know that this is how you change it in Objective-C:

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont, nil] forState:UIControlStateNormal];

但我如何将其翻译成 Swift?

But how can I translate this into Swift?

推荐答案

UITextAttributeFont 在 iOS 7 中已弃用.您应该改用 NS 变体:

The UITextAttributeFont was deprecated in iOS 7. You should use the NS variant instead:

import UIKit

let appearance = UITabBarItem.appearance()
let attributes = [NSFontAttributeName:UIFont(name: "American Typewriter", size: 20)]
appearance.setTitleTextAttributes(attributes, forState: .Normal)

这篇关于在 Swift 中更改标签栏字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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