iOS UIKit框架学习—UITabBar

UITabBar是一个应用之前不同子任务、视图和模式之间选择控制。通常情况下,UITabBar是和UITabBarController配合使用,但是你也可一把他当做单独的控件使用。标签栏总是出现在屏幕的底部边缘和显示一个或多个的内容UITabBarItem的对象。标签栏的外观可以使用背景图片或色调颜色进行自定义,以满足界面的需要。点击项目将选择并突出显示该项目,并使用该项目的选择为应用启用相应的模式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
@class UITabBarItem;
@class UIImageView;
@protocol UITabBarDelegate;
NS_CLASS_AVAILABLE_IOS(2_0) @interface UITabBar : UIView
// 代理
@property(nullable, nonatomic, weak) id<UITabBarDelegate> delegate;
// 填充的UITabBarItem数组
@property(nullable, nonatomic, copy) NSArray<UITabBarItem *> *items;
// 当前选中的item
@property(nullable, nonatomic, weak) UITabBarItem *selectedItem;
// 设置标签栏项目可选动画
- (void)setItems:(nullable NSArray<UITabBarItem *> *)items animated:(BOOL)animated;
// 可以自定义标签栏
- (void)beginCustomizingItems:(NSArray<UITabBarItem *> *)items __TVOS_PROHIBITED;
// 隐藏自定义的标签栏
- (BOOL)endCustomizingAnimated:(BOOL)animated __TVOS_PROHIBITED;
// 是否可以自定义标签栏
#if UIKIT_DEFINE_AS_PROPERTIES
@property(nonatomic, readonly, getter=isCustomizing) BOOL customizing __TVOS_PROHIBITED;
#else
- (BOOL)isCustomizing __TVOS_PROHIBITED;
#endif
// 标签栏的底部色值
@property(null_resettable, nonatomic, strong) UIColor *tintColor NS_AVAILABLE_IOS(5_0);
// 标签栏背景的底部色值
@property(nullable, nonatomic, strong) UIColor *barTintColor NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR; // default is nil
// 未被选中标签栏的item被渲染的颜色
@property (nonatomic, readwrite, copy, nullable) UIColor *unselectedItemTintColor NS_AVAILABLE_IOS(10_0) UI_APPEARANCE_SELECTOR;
// 被选中itme的渲染图片颜色
@property(nullable, nonatomic, strong) UIColor *selectedImageTintColor NS_DEPRECATED_IOS(5_0,8_0,"Use tintColor") UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
// 标签栏的背景图片
@property(nullable, nonatomic, strong) UIImage *backgroundImage NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
// 选择指示器的图片
@property(nullable, nonatomic, strong) UIImage *selectionIndicatorImage NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
// 边框图片
@property(nullable, nonatomic, strong) UIImage *shadowImage NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
// 标签栏中标签项目的定位方案
@property(nonatomic) UITabBarItemPositioning itemPositioning NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
// 标签栏项目的宽度
@property(nonatomic) CGFloat itemWidth NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;
// 标签项目的空格数量
@property(nonatomic) CGFloat itemSpacing NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;
// 标签栏风格
@property(nonatomic) UIBarStyle barStyle NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
// 是否半透明 默认是YES
@property(nonatomic,getter=isTranslucent) BOOL translucent NS_AVAILABLE_IOS(7_0);
@end
//___________________________________________________________________________________________________
@protocol UITabBarDelegate<NSObject>
@optional
// 当用户选择项目的时候调用
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;
// 自定定义视图显示之前调用
- (void)tabBar:(UITabBar *)tabBar willBeginCustomizingItems:(NSArray<UITabBarItem *> *)items __TVOS_PROHIBITED;
// 自定义视图显示后调用
- (void)tabBar:(UITabBar *)tabBar didBeginCustomizingItems:(NSArray<UITabBarItem *> *)items __TVOS_PROHIBITED;
// 自定义将要消失调用
- (void)tabBar:(UITabBar *)tabBar willEndCustomizingItems:(NSArray<UITabBarItem *> *)items changed:(BOOL)changed __TVOS_PROHIBITED;
// 自定义视图消失后调用
- (void)tabBar:(UITabBar *)tabBar didEndCustomizingItems:(NSArray<UITabBarItem *> *)items changed:(BOOL)changed __TVOS_PROHIBITED;
@end
// 标签栏的布局方式
typedef NS_ENUM(NSInteger, UITabBarItemPositioning) {
UITabBarItemPositioningAutomatic, // 自动
UITabBarItemPositioningFill, // 充满
UITabBarItemPositioningCentered, // 居中
} NS_ENUM_AVAILABLE_IOS(7_0);