【问题标题】:iOS Setting navigation item title view frame glitches on iPhone 6 and upiOS 在 iPhone 6 及更高版本上设置导航项标题视图框架故障
【发布时间】:2015-11-06 05:52:13
【问题描述】:

我将UIButton 用于navigation item title view,并且按钮的宽度可能会发生变化,因此我将框架设置如下:

CGFloat titleButtonTextWidth = [title sizeWithAttributes:@{NSFontAttributeName:FontMedium(14)}].width;
CGFloat buttonWidth = MAX(titleButtonTextWidth, SCREEN_WIDTH/3.f);

self.titleButton.frame = CGRectMake(0, 0, buttonWidth, 30);

在 iPhone 5s 及更低版本上,标题按钮位于中间,但对于 iPhone 6 及更高版本,frameorigin 受到尊重,标题按钮最终位于左上角。解决这个问题很容易,但我不知道为什么苹果决定突然改变这样的事情。

你们认为这可能是一个错误还是一个变化?

【问题讨论】:

    标签: ios objective-c iphone uinavigationitem titleview


    【解决方案1】:
    CGFloat titleButtonTextWidth = [title sizeWithAttributes:@{NSFontAttributeName:FontMedium(14)}].width;
    CGFloat buttonWidth = MAX(titleButtonTextWidth, SCREEN_WIDTH/3.f);
    
    self.titleButton.frame = CGRectMake(0, 0, buttonWidth, 30);
    self.titleButton.titleLabel.frame = CGRectMake(0, 0, buttonWidth, 30);
    

    将您的代码更改为此,这将使标题进入按钮中间。您可以相应地更改您的按钮框架

    【讨论】:

      猜你喜欢
      • 2019-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 2011-01-17
      相关资源
      最近更新 更多