IOS开发-导航栏相关设置

隐藏导航栏底部的线条
方法1 (单页面设置)

 [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
 [self.navigationController.navigationBar setShadowImage:[UIImage new]];

如果不想影响其他页面的导航透明度,viewWillDisappear将其设置为nil即可:

[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];

方法2(全局设置)

[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];

[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];

方法3

self.navigationController.navigationBar.clipsToBounds = YES;

设置导航栏底部线条颜色的代码:

UINavigationBar *navigationBar = self.navigationController.navigationBar; 
[navigationBar setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; //此处使底部线条颜色为红色
[navigationBar setShadowImage:[UIImage imageWithColor:[UIColor redColor]]];

@implementation UIImage (ColorImage)
+ (UIImage *)imageWithColor:(UIColor *)color{ 
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); 
UIGraphicsBeginImageContext(rect.size); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetFillColorWithColor(context, [color CGColor]); 
CGContextFillRect(context, rect); 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); return image;
}
@end

navigationController侧滑关闭失效的问题

self.navigationController.interactivePopGestureRecognizer.delegate = (id)self

隐藏返回按钮后面的文字

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                forBarMetrics:UIBarMetricsDefault];

最好就是自己自定义这个按钮了

你可能感兴趣的:(iOS开发,ios开发,导航,导航栏黑线)