【问题标题】:Set text font size of leftbarbuttonitem in iOS7在iOS7中设置leftbarbuttonitem的文本字体大小
【发布时间】:2013-11-24 18:51:29
【问题描述】:

所以我已经能够像这样更改 UINavigationBar 中主要文本的文本大小和颜色:

    [[UINavigationBar appearance] setTitleTextAttributes:@{
                                                       UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
                                                       UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
                                                       UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
                                                       UITextAttributeFont: [UIFont fontWithName:@"Arial-Bold" size:0.0],
                                                       }];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

但是,leftbarbuttonitem 的字体还是太大了。如何引用 leftbarbuttonitem 以便为它设置文本样式?

我尝试过类似的东西

[UINavigationBar leftBarButtonItem]
[[UINavigationBar navigationItems] leftBarButtonItem]
[[UINavigationBar appearance] leftBarButtonItem]
// and many others
etc...

但是xcode一直抱怨它不存在,我一直无法引用它。

谁能告诉我如何根据我上面的代码设置 leftBarButtonItem 的文本大小?

谢谢

【问题讨论】:

    标签: uinavigationbar


    【解决方案1】:

    以下将起作用:

    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:(NSDictionary *) forState:(UIControlState)];

    请注意,UINavigationBar 使用 UIBarButtonItem,因此当该对象包含在特定视图中时(由其类引用),您需要设置该对象的样式。这适用于其他几个地方。另一个用例可能是这样,其中 A、B 和 C 是 3 个不同的 UINavigationControllers

    [[UIBarButtonItem appearanceWhenContainedIn:[A class], [B class], nil] setTitleTextAttributes:(NSDictionary *) forState:(UIControlState)];

    [[UIBarButtonItem appearanceWhenContainedIn:[C class], nil] setTitleTextAttributes:(NSDictionary *) forState:(UIControlState)];

    在上面的示例中,UINavigationControllers A 和 B 中的 UIBarButtonItems 将获得类似的样式,而 UINavigationController C 的 UIBarButtonItems 将具有自己独特的样式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-08
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 2013-03-05
      相关资源
      最近更新 更多