UITabBarController介绍:2-UITabBar的常用属性和方法
UITabBar类对象tabBar是UITabBarController中的一个属性,其负责定义底部功能栏的整体外观样式,但每个菜单按钮的样式并不是由UITabBar类对象控制的,而是有各个子控制器中的tabBarItem(UITabBarItem类)属性决定的。
UITabBar的常用属性和方法
UITabBar类中定义了如下一些方法,主要用于定制底部菜单栏的整体外观样式。
- tintColor: tabBar整体渲染的颜色
@property(null_resettable, nonatomic, strong) UIColor *tintColor;
默认情况下,渲染的颜色是蓝色,我们可以通过修改tintColor属性来修改整体渲染的颜色。如下对比图。
tabBarVC.tabBar.tintColor = [UIColor redColor];
- barTintColor: tabBar的整体背景颜色。例如,我们可以修改其为黄色。
@property(nullable, nonatomic, strong) UIColor *barTintColor;
tabBarVC.tabBar.barTintColor = [UIColor yellowColor];
- backgroundImage: 为tabBar设置背景图片
@property(nullable, nonatomic, strong) UIImage *backgroundImage;
tabBarVC.tabBar.backgroundImage = [UIImage imageNamed:@"tabbarBkg"];
默认情况以及设置了一张图片作为背景图片的对比,如下所示:
- barStyle:tabBar的整体风格样式,默认为白色的,可以改为黑色
@property(nonatomic) UIBarStyle barStyle;
typedef NS_ENUM(NSInteger, UIBarStyle) {
UIBarStyleDefault = 0,
UIBarStyleBlack = 1,
}
修改为黑色后的样式如下所示,即黑色背景+白色文字
- items: 获取tabBar上面的所有UITabBarItem类的对象,即底部菜单栏上面的按钮,可以对其样式进行修改。
@property(nullable, nonatomic, copy) NSArray<UITabBarItem *> *items;
素材下载
本案例中使用的素材请到github下载,下载地址:九九学院素材库.
- 使用素材名称:WeChatTabBar.zip
文章发布时间为: November 1st , 2016 at 09:51 am
最后编辑时间为: September 13th , 2017 at 03:04 pm
本文由 99ios 创作,转载请注明出处
最后编辑时间为: September 13th , 2017 at 03:04 pm
本文由 99ios 创作,转载请注明出处