1

I am using a UIButton for navigation item title view, and the width of the button is subject to change, so I'm setting the frame like below:

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

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

On iPhone 5s and lower, the title button stays at the middle, but for iPhone 6 and up, the origin of the frame is respected and the title button ends up in the top-left corner. Solving this is easy, but I don't know why Apple decided to suddenly change things like this.

Do you guys think this might be a bug or a change?

funct7
  • 3,407
  • 2
  • 27
  • 33

1 Answers1

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

change your code to this, this will make title to go in middle of button. You can change your button frame accordingly

S.Jain
  • 441
  • 4
  • 9