gpt4 book ai didi

swift - 在 Swift 中更改标签栏字体

转载 作者:IT王子 更新时间:2023-10-29 05:08:41 24 4
gpt4 key购买 nike

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

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

但是我怎样才能将它翻译成 Swift 呢?

最佳答案

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

import UIKit

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

关于swift - 在 Swift 中更改标签栏字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26069334/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com