【问题标题】:UIBarButtonItem Custom Font Wrong Size (Updates on touch)UIBarButtonItem 自定义字体大小错误(触摸更新)
【发布时间】:2013-03-30 01:54:17
【问题描述】:

你可以在这里看到它发生:

http://www.screencast.com/t/mSveqUgPe1

与我的问题类似:UIBarButtonItem Custom Background Appearance 'Jumping' after flip transition

这似乎完全是通过外观 api 为UIBarButtonItems 设置自定义字体引起的。

[[UIBarButtonItem appearance] setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
  [UIColor colorWithRed:1 green:1 blue:1 alpha:1.0],
  UITextAttributeTextColor,
  [UIColor colorWithRed:4/255.0 green:4/255.0 blue:4/255.0 alpha:0.5],
  UITextAttributeTextShadowColor,
  [NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
  UITextAttributeTextShadowOffset,
  [UIFont fontWithName:@"ProximaNova-Bold" size:16.0],
  UITextAttributeFont,
  nil] forState:UIControlStateNormal];

如果我只注释掉字体部分,它就可以解决问题。即使使用像 Helvetica 这样的非自定义字体,以这种方式设置也会导致同样的问题。之前调整图像偏移的 hack 不适用于这个,所以尝试寻找另一种解决方法。

【问题讨论】:

    标签: cocoa-touch ios6


    【解决方案1】:

    显然这是一个错误,但这次我在代码中找到了一个新的解决方法。

    - (void)viewWillLayoutSubviews {
        [super viewWillLayoutSubviews];
        self.navigationItem.rightBarButtonItem.title = @"NEXT";
    }
    

    在调用super viewWillLayoutSubviews 后在代码中设置标题有效。至于为什么会修复它...不知道。

    不完全

    现在它在跳跃。它呈现错误,然后更新到正确的位置/大小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 2016-11-21
      相关资源
      最近更新 更多