Change the height of NavigationBar and UIBarButtonItem elements inside it in Cocoa Touch

后端 未结 6 2077
忘了有多久
忘了有多久 2020-12-23 15:19

I suppose it\'s not strictly in line with Apple guidelines but I guess it must be possible somehow. I\'d like to change the height of navigation bar inside UINavigationContr

6条回答
  •  悲哀的现实
    2020-12-23 15:51

    For the UINavigationbar

    In iOS SDK 4.3 and beyond, there is a way (hack) to change the height of the UINavigationBar.

    To change the height of UINavigationController, change its frame size in viewWillAppear:animated: function. Then, the height will stay customized throughout whole app.

    For the UIBarButtonItems
    I've actually run into this myself and the only thing I could come up with was leveraging initWithCustomView and passing in a UIButton with a defined frame.

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    /*
    * Insert button styling
    */
    
    button.frame = CGRectMake(0, 0, width, height);
    
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    

    Otherwise UIBarButtonItem only has a width property that can be set but unfortunately not a height property. Another nifty thing I've done with initWithCustomView is to pass in a toolbar with a button and other things like activity indicators. Hope this helps.

提交回复
热议问题