iOS隱藏導航欄底部的線條& UINavigationBar小技巧


隱藏導航欄底部的線條

轉載: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




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM