Adjusting navigationItem.titleView's frame?

前端 未结 13 1562
小蘑菇
小蘑菇 2021-01-31 04:14

I noticed that the titleView\'s position depends on the rightbarbutton title. How can I set the frame of the titleView to be in the center instead?

I\'ve tried setting

13条回答
  •  一整个雨季
    2021-01-31 04:28

    You can try set the frame to CGRectZero initially and call sizeToFit. Below is the code I used to change the title text and made sure it is still centered. I had a back button on the left.

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];    
    label.text = @"Title";
    [label sizeToFit];
    self.navigationItem.titleView = label;
    

提交回复
热议问题