刪除navigationBar下面的橫線方法
- 聲明用來存放下方橫線的屬性
_navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
- 設(shè)置找到該橫線的方法
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
/** 如果這個類是UIImageView類并且高度小于1 的話直接返回. */
if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
return (UIImageView *)view;
}
/** 遍歷傳入的view上面的子視圖. */
for (UIView *subView in view.subviews) {
/** 回調(diào)此方法. 直到找到下方橫線的ImageView并返回*/
UIImageView *imageView = [self findHairlineImageViewUnder:subView];
if (imageView) {
return imageView;
}
}
return nil;
}
- 在
- (void)viewWillAppear:(BOOL)animated
和- (void)viewWillDisappear:(BOOL)animated
兩個方法中設(shè)置view 的隱藏.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_navBarHairlineImageView.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
_navBarHairlineImageView.hidden = NO;
}
這樣就可以是下方的橫線消失.
設(shè)置title字體顏色和大小
self.navigationItem.title = @"通訊錄";
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:18]};
設(shè)置leftBarButtonItem的顏色
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];