iOS开发之navigationbar,tabbar

Navigation Controller Views

A navigation controller is a container view controller—that is, it embeds the content of other view controllers inside of itself. You access a navigation controller’s view from its view property. This view incorporates the navigation bar, an optional toolbar, and the content view corresponding to the topmost view controller. Figure 3 shows how these views are assembled to present the overall navigation interface. (In this figure, the navigation interface is further embedded inside a tab bar interface.) Although the content of the navigation bar and toolbar views changes, the views themselves do not. The only view that actually changes is the custom content view provided by the topmost view controller on the navigation stack.

iOS开发之navigationbar,tabbar_第1张图片
视图层次结构

以上是从官方文档copy过来的,大致意思就是导航控制器是一个容器视图控制器,这个容器是以 的形式管理的

我们以这种方式的跳转像pop push 等就非常容易理解了,初始化的时候rootViewController也就很容易理解了

文档中个人觉得需要注意的地方:

The navigation controller manages the creation, configuration, and display of the navigation bar and optional navigation toolbar. It is permissible to customize the navigation bar’s appearance-related properties but you must never change its frame, bounds, or alpha values directly. If you subclass UINavigationBar, you must initialize your navigation controller using the initWithNavigationBarClass:toolbarClass: method. To hide or show the navigation bar, use the navigationBarHidden property or setNavigationBarHidden:animated: method.

翻译:导航控制器管理创建,配置和导航栏和可选的导航工具栏的显示。它允许自定义导航栏的外观相关的属性,但你绝不能直接改变它的框架,边界,或alpha值。 方法如果你继承UINavigationBar的,则必须使用initWithNavigationBarClass初始化导航控制器。要隐藏或显示导航栏,使用navigationBarHidden属性或setNavigationBarHidden :动画:方法。


下面讲解一下自定义导航栏 navigationBar 的外观

先上效果图(仿微信的)


效果图

直接上代码:(注释还是比较清晰的)

    // 获取navigationBar
    UINavigationBar *bar = [UINavigationBar appearance];
    
    CGFloat rgb = 0.1;

   // bar tint color
    bar.barTintColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.9];
    
    // tint color
    bar.tintColor = [UIColor whiteColor];
    
    // 设置title前景色
    bar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
    
    // barStyle样式苹果推荐了两种
    // bar.barStyle = UIBarStyleBlack;
    
    // 设置bar的透明度
    // bar.translucent = NO;
    
    // 取消bar下面的分割线,
    bar.shadowImage = [UIImage new];
    
    // 还原bar下面的分割线,设为nil就还原了,神奇吧\(^o^)/~
    // bar.shadowImage = nil;

    // 可以设置背景图片
    // [self.navigationBar setBackgroundImage:navBgImg forBarMetrics:UIBarMetricsDefault];

当然也可以自定义一个navigationController,然后去设置其navigationBar的外观

注意:

个人建议,如果没有特殊需求,项目中就用同一个navigationController,毕竟就是一个容器的作用。(被坑过的人,你们懂得)


tabbar的外观修改可以类比navigationbar,也是一个容器


希望会给大家带来帮助O(∩_∩)O

你可能感兴趣的:(iOS开发之navigationbar,tabbar)