祛除导航栏白边
self.navigationController.navigationBar.translucent = NO;
[self.navigationController.navigationBar setBackgroundImage: [UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
self.navigationController.navigationBar.hidden = NO;
[self.navigationController.navigationBar setBackgroundImage:[self imageWithBgColor:[UIColor colorWithRed:0 green:0 blue:0 alpha: self.newsTableView.contentOffset.y / 200]] forBarMetrics:UIBarMetricsDefault];if(scrollView.contentOffset.y > 44){
self.navigationItem.title = @”发现”;
}if(scrollView.contentOffset.y < 44){
self.navigationItem.title = @”“;
}
}
-(UIImage )imageWithBgColor:(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;
}
第二种方式:
pragma AutoShow - NavigationView
(void)setupNavigationTitle
{
self.navBackView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, SCREEN_WIDTH, 64)];
[self.view addSubview: self.navBackView];UILabel *navigationTitleLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 100, 44)];
navigationTitleLabel.textAlignment = NSTextAlignmentCenter;
navigationTitleLabel.textColor = [UIColor whiteColor];
navigationTitleLabel.text = @”\U0000e612”;
navigationTitleLabel.font = [UIFont fontWithName: FONT_NAME_ICON size: 19];
navigationTitleLabel.center = self.navBackView.center;
self.navigationTitleLabel = navigationTitleLabel;
[self.navBackView addSubview: self.navigationTitleLabel];
}(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
self.navBackView.backgroundColor = [UIColor colorWithPatternImage: [JIHUtils imageFromColor: [UIColor colorWithRed:0 green:0 blue:0 alpha: self.newsTableView.contentOffset.y / 200]]];
self.navigationTitleLabel.textColor = [UIColor colorWithWhite: 1 alpha: self.newsTableView.contentOffset.y / 200];
}(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:YES];
}(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
self.navigationController.navigationBar.hidden = YES;
}