iOS - UinavigationController

导航条颜色

要在-(void)viewWillAppear:(BOOL)animated;方法设置
1.iOS7之后 要想改变navigationbar的颜色 可以这样子改

self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#3A3A3A" alpha:1.0f];
//默认带有一定透明效果,可以使用以下方法去除系统效果
[self.navigationController.navigationBar setTranslucent:NO];

2,//设施导航控制器导航栏的背景图片(遮盖后面的过度黑影(系统自带))

[self.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];

3,设置背景图片(如果图片消炎药拉伸,需要对图片进行拉伸设置)

UIImage *image = [UIImage imageNamed:@"navigation_bg"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

导航栏的搜索框

  UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 50, 40)];
    searchBar.delegate = self;
    searchBar.placeholder = @"输入物流公司进行查找";
    self.searchBar = searchBar;
    self.navigationItem.titleView = searchBar;

设置字体颜色

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor colorWithHex:@"545454"],NSFontAttributeName : [UIFont systemFontOfSize:19]};

隐藏导航条

    [self.navigationController setNavigationBarHidden:NO animated:YES];
去掉阴影线    //去掉黑色线   
 [self.tabBar setShadowImage:[[UIImage alloc] init]];

隐藏导航条返回按钮

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.navigationItem.leftBarButtonItem = nil;
    self.navigationItem.hidesBackButton = YES;
}

titleView居中

效果:
红色的为titleview,绿色的为居中的view

UIView *title_ve = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)];
    title_ve.backgroundColor = [UIColor redColor];
    
    //设置titleview,不过这个view并不是我们需要的居中的view;
    self.navigationItem.titleView = title_ve;
    
    __weak typeof(self) weakSelf = self;
    //主线程列队一个block, 这样做 可以获取到autolayout布局后的frame,也就是titleview的frame。在viewDidLayoutSubviews中同样可以获取到布局后的坐标
    dispatch_async(dispatch_get_main_queue(), ^{
        //要居中view的宽度
        CGFloat width = 120;
        //实际居中的view
        UIView *center_ve = [[UIView alloc]init];
        center_ve.backgroundColor = [UIColor greenColor];
        //设置一个基于window居中的坐标
        center_ve.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width-width)/2, 20, width, 44);
        //坐标系转换到titleview
        center_ve.frame = [weakSelf.view.window convertRect:center_ve.frame toView:weakSelf.navigationItem.titleView];
        //centerview添加到titleview
        [weakSelf.navigationItem.titleView addSubview:center_ve];
    });

设置 baritem 出现的颜色

[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:tab_dynamic_color} forState:UIControlStateSelected];
        [
[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:color_dark_gray} forState:UIControlStateNormal];

加载 时隐藏 tabbar

UIV.hidesBottomBarWhenPushed = YES;

你可能感兴趣的:(iOS - UinavigationController)