先上效果圖:
1.首先需要一張純透明的png圖片設置為navigationBar的背景
<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+CiAgICBbc2VsZi5uYXZpZ2F0aW9uQ29udHJvbGxlci5uYXZpZ2F0aW9uQmFyCnNldEJhY2tncm91bmRJbWFnZTpbVUlJbWFnZQppbWFnZU5hbWVkOkA="未標題-1.png"] forBarMetrics:UIBarMetricsDefault];
2.執行完上面那行代碼後發現navigationBar設置為透明了,但是在Bar的下方會有一條“線”。就是下圖的樣子。
想要實現徹底的透明需要再加幾行代碼:
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
NSArray *list = self.navigationController.navigationBar.subviews;
for (id obj in list) {
if ([obj isKindOfClass:[UIImageView class]]) {
UIImageView *imageView = (UIImageView *)obj;
imageView.hidden = YES;
}
}
}
如有疑問,歡迎留言~