Tabbar中的自定义字体

时间:2011-06-01 18:39:30

标签: iphone objective-c fonts uitabbarcontroller

嘿,
有没有办法将tabbar的字体设置为例如黑板?我已经看到了字体大小的问题,并尝试使用字体,但循环无法解决。

如果无法使用自定义字体,是否可以删除所有文本并使标签栏的项目覆盖整个标签?或者我可以以某种方式将imageView放在标签栏的顶部并使用标签“通过”该图像?

谢谢!

3 个答案:

答案 0 :(得分:6)

我发现自己是一本非常棒的教程,可以完全满足我的需求。 为了进一步参考,可能还需要这一点,这里是链接

Part 1

Part 2

答案 1 :(得分:5)

放入AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

以下是代码:

    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary: [[UITabBarItem appearance] titleTextAttributesForState:UIControlStateNormal]];
[attributes setValue:[UIFont fontWithName:@"Avenir" size:10] forKey:UITextAttributeFont];
[[UITabBarItem appearance] setTitleTextAttributes:attributes1 forState:UIControlStateNormal];

答案 2 :(得分:0)

在iOS 13上,UITabBarItem.appearance().setTitleTextAttributes方法存在错误,因此我们需要采取以下解决方法:

    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.alignment = .center
    let attributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12),
                      NSAttributedString.Key.paragraphStyle: paragraphStyle]

    let appearance = UITabBarItem.appearance()
    appearance.setTitleTextAttributes(attributes, for: .normal)

    if #available(iOS 13.0, *) {
        let appearance = UITabBarAppearance()
        appearance.stackedLayoutAppearance.normal.titleTextAttributes = attributes
        appearance.stackedLayoutAppearance.normal.badgeBackgroundColor = .blue
        appearance.stackedLayoutAppearance.selected.titleTextAttributes = attributes
        appearance.stackedLayoutAppearance.selected.badgeBackgroundColor = .blue
        tabBar.standardAppearance = appearance
    }

如果仅在iOS 13上设置外观tabBar.standardAppearance = appearance,您仍然会遇到错误,而另一个错误