[英]iOS Setting navigation item title view frame glitches on iPhone 6 and up
我將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及更高版本上, frame
的origin
得到尊重,標題按鈕最終位於左上角。 解決這個問題很容易,但是我不知道為什么蘋果公司決定突然改變這樣的事情。
你們認為這可能是錯誤還是更改?
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);
將您的代碼更改為此,這將使標題位於按鈕中間。 您可以相應地更改按鈕框
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.