码迷,mamicode.com
首页 > 移动开发 > 详细

iOS隐藏导航栏底部的线条& UINavigationBar小技巧

时间:2018-04-08 10:52:04      阅读:354      评论:0      收藏:0      [点我收藏+]

标签:透明   rap   text   keyword   bottom   rom   objective   clip   offset   

隐藏导航栏底部的线条

转载:https://www.jianshu.com/p/aa547432eae0

方法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];

参考文章:
http://www.jianshu.com/p/f0d3df54baa6
http://stackoverflow.com/questions/19226965/how-to-hide-ios7-uinavigationbar-1px-bottom-line
http://stackoverflow.com/questions/22090314/restore-navigationbar-background-image-after-setting-it-to-uiimage-new



iOS隐藏导航栏底部的线条& UINavigationBar小技巧

标签:透明   rap   text   keyword   bottom   rom   objective   clip   offset   

原文地址:https://www.cnblogs.com/nelsen-chen/p/8743410.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!