去掉导航栏分割线 和 设置导航栏的背景颜色

    // 去掉导航栏下面的 分割线
    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;
                NSArray *list2=imageView.subviews;
                for (id obj2 in list2) {
                    if ([obj2 isKindOfClass:[UIImageView class]]) {
                        UIImageView *imageView2=(UIImageView *)obj2;
                        imageView2.hidden=YES;
                    }
                }
            }
        }
    }
- (void)setNavigationBar
{
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.edgesForExtendedLayout = UIRectEdgeTop; // 顶部开始
    self.navigationController.navigationBar.translucent  = YES; // 导航栏透明
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"barpic1"] forBarMetrics:UIBarMetricsDefault]; // 添加背景颜色(图片)(主要的 如果要把导航栏设置成透明的··用一张透明的图片就好了)
    //设置导航栏文字为白色
    self.navigationController.navigationBar.titleTextAttributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor, nil];
    //设置后退按钮为白色
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    //设置后退按钮统一为返回
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
}

效果如下
去掉导航栏分割线 和 设置导航栏的背景颜色_第1张图片

你可能感兴趣的:(iOS随手记)