UINavigationItem titleView position

前端 未结 7 751
长发绾君心
长发绾君心 2021-02-13 03:45

I\'m using UINavigationItem\'s titleView property to set a custom UILabel with my desired font size/color. Here\'s my code:

self.headerLabel = [[UILabel alloc] i         


        
相关标签:
7条回答
  • 2021-02-13 04:15

    What worked for me was to update the titleView frame in the viewDidAppear method.

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    
        UIView *titleView = self.navigationItem.titleView;
        CGRect navBarFrame = self.navigationController.navigationBar.frame;
        [titleView setFrame:CGRectMake((CGRectGetWidth(navBarFrame) - TitleWidth) / 2, (CGRectGetHeight(navBarFrame) - TitleHeight) / 2, TitleWidth, TitleHeight)];
    }
    
    0 讨论(0)
提交回复
热议问题