如何在iOS标签栏中使用自定义字体

Mat*_*ack 16 objective-c ios7

我正在为我的iPhone应用程序的UI使用字体很棒的资源: FontAwesome

我在我的应用程序屏幕中使用它,如下所示:

Phone.font = [UIFont fontWithName:kFontAwesomeFamilyName size:40];
Phone.text = [NSString fontAwesomeIconStringForIconIdentifier:@"fa-phone"];
Run Code Online (Sandbox Code Playgroud)

但现在我想在我的标签栏控制器的标签栏项目中使用它,即我想将标签栏的图标设置为字体真棒元素.如何才能做到这一点?

Paw*_*Rai 30

根据:如何在iOS 5中更改UITabBarItem中的文本颜色

看起来解决方案可能是将消息发送到外观代理,而不是一个项目:

[[UITabBarItem appearance] setTitleTextAttributes:@{
                                                    NSFontAttributeName:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f]
                                                    } forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)

这里有一些参考

如何对变化的颜色型的文本功能于uitabbaritem功能于IOS-5

iOS5的-的TabBar的字体和颜色


sup*_*org 9

Swift版本:

    UITabBarItem.appearance().setTitleTextAttributes(
            [NSFontAttributeName: UIFont(name:"Ubuntu", size:11)!, 
                NSForegroundColorAttributeName: UIColor(rgb: 0x929292)], 
            forState: .Normal)
Run Code Online (Sandbox Code Playgroud)


Nik*_*las 7

斯威夫特3

UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name:"Latio-Regular", size:14)!, NSForegroundColorAttributeName: UIColor.white], for: .normal)
Run Code Online (Sandbox Code Playgroud)