How can I get a full-sized UINavigationBar titleView

前端 未结 6 1502
遇见更好的自我
遇见更好的自我 2020-12-25 14:25

I am trying to add a custom control as the titleView in a UINavigationBar. When I do so, despite setting the frame and the properties that would normally assume full width,

6条回答
  •  礼貌的吻别
    2020-12-25 14:44

    Setting the titleView of your view's navigationItem will never do the trick. Instead, you can add a subView to the navigation controller's navigationBar :

    UIView* ctrl = [[UIView alloc] initWithFrame:navController.navigationBar.bounds];
    ctrl.backgroundColor = [UIColor yellowColor];
    ctrl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [navController.navigationBar addSubview:ctrl];
    

提交回复
热议问题