1.设置navigationItem.leftBarButtonItem 会覆盖掉系统自带的返回图标+返回title
UIImage *image=[UIImage imageNamed:@"btn_arrow_left_normal"];
UIButton *backButton=[UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame=CGRectMake(0, 0, image.size.width, image.size.height);
[backButton setBackgroundImage:image forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(doBack) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backItem;
2.设置导航栏标题 title 属性
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
RGBCOLOR(0xff, 0xff, 0xff), UITextAttributeTextColor,
[UIColor colorWithRed:0 green:0.7 blue:0.8 alpha:1], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,
[UIFont systemFontOfSize:20.0], UITextAttributeFont, nil]];
3.自定义导航栏右边按钮
UIButton rightSearch = [UIButton buttonWithType:UIButtonTypeCustom];
[rightSearch setBackgroundImage:[UIImage imageNamed:@"right_search"] forState:UIControlStateNormal];
[rightSearch addTarget:self action:@selector(doSearchTask:) forControlEvents:UIControlEventTouchUpInside];
rightSearch.frame = CGRectMake(0, 0, 20, 20);
UIBarButtonItem *settingNavBar = [[UIBarButtonItem alloc] initWithCustomView:rightSearch];
self.navigationItem.rightBarButtonItem = settingNavBar;
4. 定制颜色
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];//iOS7 later 修改导航栏背景颜色
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"btn_arrow_left_normal"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"btn_arrow_left_normal"]]; //这两个属性必须同时修改才能修改返回按钮的图标,都是iOS7Later
if (IOS7_OR_LATER) { //直接修改导航栏背景图片,注意iOS6和iOS7导航栏的区别
[[UINavigationBar appearance] setBackgroundImage:[DXImageUtil imageWithColor:RGBCOLOR(0xff, 0x67, 0x00) andBounds:CGRectMake(0, 0, 320, 64)] forBarMetrics:UIBarMetricsDefault];
} else {
[[UINavigationBar appearance] setBackgroundImage:[DXImageUtil imageWithColor:RGBCOLOR(0xff, 0x67, 0x00) andBounds:CGRectMake(0, 0, 320, 44)] forBarMetrics:UIBarMetricsDefault];
}
5. 修改状态栏属性或者方法
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
设置此属性时,请注意文档说法:// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.如果想要正确使用这两个方法,我们需要在app-Info.plist中添加:
key : View controller-based status bar appearance value为:NO。否则不起任何作用