1

我正在使用UIButtonfor 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 及更高版本,the originof theframe受到尊重,标题按钮最终位于左上角。解决这个问题很容易,但我不知道为什么苹果决定突然改变这样的事情。

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

4

1 回答 1

0
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);

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

于 2015-11-06T07:05:36.003 回答