小编典典

在Swift中更改标签栏字体

swift

我一直在尝试更改选项卡栏项目的字体,但是我找不到任何Swift示例。我知道这是您在Objective-C中进行的更改:

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

但是如何将其转换为Swift?


阅读 303

收藏
2020-07-07

共1个答案

小编典典

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

import UIKit

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