簡單的說,就是用一張純色的圖片來代替陰影線。
那么,直接上代碼。
首先獲取一個純色圖片
- (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; }
替換掉navigationBar的ShadowImage
UIImage *image = [self imageWithColor:[[UIColor whiteColor] colorWithAlphaComponent:1]]; ////設置NavBar的背景 [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; ////去除陰影分割線的方法 [self.navigationController.navigationBar setShadowImage:image]; self.navigationController.navigationBar.translucent = NO;
好了修改成功。