【问题标题】:Changing the font in a UITabBar更改 UITabBar 中的字体
【发布时间】:2014-10-12 12:16:08
【问题描述】:

我想知道是否有人可以帮助我解决我目前遇到的问题。我正在尝试更改UITabBar 的实际字体,我已经能够在选择文本时选择文本颜色和颜色。我到目前为止的代码在这里:

//Setting tab bar background
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
//[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selected.png"]];

// Changes Selected Image color
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:33.0/255.0 green:35.0/255.0 blue:38.0/255.0 alpha:1.0]]; //Icon colour

// Changes StateNormal text Color,
[UITabBarItem.appearance setTitleTextAttributes: @{NSForegroundColorAttributeName : [UIColor colorWithRed:214.0/255 green:69.0/255 blue:65.0/255 alpha:1.0]} forState:UIControlStateNormal]; //Colour of text when not seleted

// Changes StateSelected
UIColor *titleHighlightedColor = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0]; //Colour of text when selected

[UITabBarItem.appearance setTitleTextAttributes: @{NSForegroundColorAttributeName : titleHighlightedColor} forState:UIControlStateSelected];

我想知道是否有人知道是否可以在此处更改字体,如果可以,我会怎么做?代码位于 AppDelegate.m

提前致谢,
哈里森

【问题讨论】:

    标签: ios objective-c cocoa-touch fonts tabbar


    【解决方案1】:

    尝试将其添加到标题文本属性中:

    [UITabBarItem.appearance setTitleTextAttributes: @{
      NSForegroundColorAttributeName : [UIColor colorWithRed:214.0/255 green:69.0/255 blue:65.0/255 alpha:1.0],
      NSFontAttributeName : [UIFont systemFontOfSize:20]
    } forState:UIControlStateNormal]; 
    

    【讨论】:

    • 嗯,没关系...这应该可行,您是否看到任何变化?字体颜色有效吗?
    【解决方案2】:

    你可以使用

    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Arial" size:5.0f], NSFontAttributeName, nil] forState:UIControlStateNormal];
    

    【讨论】:

    • 您输入的字体名称是否正确? xcode 是否支持该字体? @BadfishLabs
    • Xcode 支持我选择的字体,是的,因为我在将字体添加为目标并进入 Plist 并将其添加到那里之前已经使用过它。
    • @BadfishLabs 我刚刚自己测试过,它工作正常,你有没有把这段代码放在你的应用程序中删除 didFinishLaunchingWithOptions 下?
    • 我现在再次测试一下,如果这不起作用,您可以通过 Skype 或其他程序与我交谈吗?谢谢
    • 不幸的是,这也不起作用:(也许你可以看看 Skype 或 Join.me?
    猜你喜欢
    • 2019-07-31
    • 2014-05-27
    • 2015-09-28
    • 1970-01-01
    • 2015-02-11
    • 1970-01-01
    • 2015-06-03
    • 2016-04-29
    • 2021-12-30
    相关资源
    最近更新 更多