UINavigationBar是一个bar,一般在窗口的顶部显示,包含多个按钮,用于在屏幕层次结构中起导航作用。 主要组件是左(后)按钮,中心标题和可选的右按钮。可以把导航栏作为独立对象使用,或与导航控制器配合使用。
导航栏默认为半透明的,即translucent属性默认为true。注:当要设置导航栏的 背景图片或背景颜色(barTintColor)时,需要把translucent属性设置为false。否则会出现色差。
tintColor属性可以设置按钮的字体颜色。
(void)setTitleVerticalPositionAdjustment:(CGFloat)adjustment forBarMetrics:(UIBarMetrics)barMetrics;设置或获取导航栏栏竖直位置偏移。
导航栏中标题的字体大小,字体颜色,字体阴影等属性可以导航栏的titleTextAttributes属性设置。
-
需要隐藏导航栏时,使用 [self.navigationController.navigationBar setHidden:YES animated:YES]]; 可以避免push或者pop时,闪屏的现象。
设置返回按钮
UIButton* leftButton = [UIButton new];
CGFloat x, y, w, h;
x = y = 0.0;
w = h = 3.0;
leftButton.frame=CGRectMake(x, y, w, h) ;
[leftButton setImage:[UIImage imageNamed:@"back" ]forState: UIControlStateNormal]
[leftButton addTarget:self action:selector forControlEvents: UIControlEventTouchUpInside] ;
UIBarButtonItem* leftBarItem = [[UIBarButtonItemalloc] initWithCustomView: leftButton] ;
self.navigationItem.leftBarButtonItem = leftBarItem ;