UINavigationItem titleView position

前端 未结 7 752
长发绾君心
长发绾君心 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)];
    }
    

提交回复
热议问题