How do i set the height of the UINavigationBar in an iphone app

非 Y 不嫁゛ 提交于 2020-01-22 02:38:05

问题


Im using a typical situation with UINavigationController, id like to make the navigation bar a bit taller. setting its bounds and frame dont seem to make a difference, im using this code

    //set up the navigation
UINavigationController *navigationController = [UINavigationController new];

[navigationController.navigationBar setBarStyle:UIBarStyleBlack];
[navigationController.navigationBar setTintColor:[UIColor purpleColor]];
[navigationController.navigationBar setBounds:CGRectMake(0.0, 0.0, 480.0, 100.0)];
[navigationController.navigationBar setFrame:CGRectMake(0.0, 0.0, 480.0, 100.0)];

but to no avail. any ideas?


回答1:


I don't think you can change the height of a navigation bar. Except when you add a prompt message... But that's not what you want.

Frame is the visible area of a view. Bounds is the internal area. Usually this has an origin of (0, 0) and is as wide and high as the frame. However, when the content exceeds the visible area (like with a UIScrollView) the bounds can be larger (and the origin different). You rarely see bounds that are smaller than their respective frames.

EDIT: Looking at your code, what is [UINavigationController new] about? You should do [[UINavigationController alloc] init], shouldn't you?

Also, what you are doing is not really subclassing...




回答2:


At the time of 2009, there is probably no way to change the height of UINavigationController. However, in iOS SDK 4.3, there is a way (hack).

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




回答3:


As far as I know the standard navigation bar height should not be changed.

"Specifically, it is alright to modify the barStyle, tintColor, and translucent properties, but you must never directly change UIView-level properties such as the frame, bounds, alpha, or hidden properties directly."

If you like to customize the appearance of navigation bar you can use the appearance proxy [UINavigationBar appearance] in iOS 5



来源:https://stackoverflow.com/questions/1385538/how-do-i-set-the-height-of-the-uinavigationbar-in-an-iphone-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!