UINavigationItem centering the title

前端 未结 7 501
深忆病人
深忆病人 2020-12-23 22:01

I have a navigationBar with both Left and Right bar buttons on each side. I have a customTitlelabel which I set as the titleView of the UINavigationItem

相关标签:
7条回答
  • 2020-12-23 22:59

    I had a similar situation where a titleView should be centered in UINavigationBar. I like occulus's approach of subclassing a UIView and overriding setFrame:. Then, I can center the frame inside the dimensions of UINavigationBar.

    In the UIView subclass:

    -(void)setFrame:(CGRect)frame{
      super.frame = CGRectMake(320 / 2 - 50, 44 / 2 - 15, 100, 30);
    }
    

    The UIView subclass can then be assigned normally to titleView for each navigationItem. The developer does not have to programmatically add and remove special subviews from UINavigationBar.

    0 讨论(0)
提交回复
热议问题