【问题标题】:UIBarButtonItem changes font after being pressed, specified in appearance proxyUIBarButtonItem 按下后改变字体,在外观代理中指定
【发布时间】:2013-11-28 00:20:48
【问题描述】:

我在AppDelegate中通过appearance代理设置了UIBarButtonItem标题字体:

[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                      [UIFont fontWithName:@"Segoe Print" size: 14.0], UITextAttributeFont,
                                                      DEF_TITLE_COLOR,UITextAttributeTextColor,
                                                      [UIColor colorWithRed:100/255 green:128/255 blue:43/255 alpha:0.4], UITextAttributeTextShadowColor,
                                                      [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, nil]
                                            forState:UIControlStateNormal&UIControlStateHighlighted&UIControlStateDisabled];

然后我在我的应用程序的某个地方调用presentViewController::。条形按钮以正确的字体和背景图像显示,这是我在此 ViewController 中设置的(不是通过外观):

但是当我按下“加入”按钮时,会显示标准的非自定义 UIAlertView,并且在它出现在屏幕上之后,我的 barButton 字体会更改为 ... 标准?颜色也看起来像浅色。我不知道我做错了什么,尝试了很多事情来弄清楚:

此错误仅出现在 iOS7 上。

【问题讨论】:

  • @user2277872 这没有帮助。有同样的问题。当我尝试使用 '|' 分隔状态时,如 null 所建议的那样,代理根本不起作用,甚至没有更改正常状态的字体。

标签: ios xcode uibarbuttonitem ios7


【解决方案1】:

好吧,我发现外观代理无法按预期工作。我在UIBarButtonItem初始化的地方之前复制粘贴了自定义方法,它起到了魅力。

【讨论】:

  • 同样 - 帮助。我已经将该 UIBarButtonItem 与情节提要连接起来。所以我尝试使用 [[UIBarButtonItem alloc] init] 重新初始化按钮并手动设置归因于它(而不是使用情节提要中的那些)。有效,但很奇怪,我认为这是 Apple 错误。
【解决方案2】:

这可能适用于 iOS 7:

viewDidLoad方法中:

[self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];

并设置字体属性。

【讨论】:

  • 此属性仅更改 backButtons 上“
猜你喜欢
  • 1970-01-01
  • 2014-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 2016-04-05
  • 1970-01-01
相关资源
最近更新 更多