DKTabPageViewController 是一个支持多标签和手势的 UIViewController 子类。每个标签代表一个 ViewController 实例,彼此独立。视图支持懒加载并响应 viewWillAppear、viewWillDisappear 等方法。添加了对顶部栏文本自定义动画的支持。
v1.4.1 - 2015年2月6日
selectedIndex
添加了 KVO。v1.4.0 - 2015年1月6日
v1.3.0 - 2015年4月15日
v1.2.0 - 2015年3月8日
v1.0.0 - 2015年1月18日
$ pod search DKTabPageViewController
-> DKTabPageViewController (1.4.1)
DKTabPageViewController is an UIViewController subclass that support for multiple
tab and gestures.
pod 'DKTabPageViewController', '~> 1.4.0'
- Homepage: https://github.com/zhangao0086/DKTabPageViewController
- Source: https://github.com/zhangao0086/DKTabPageViewController.git
- Versions: 1.2.0, 1.1.0, 1.0.0, 0.0.6, 0.0.5, 0.0.4, 0.0.3, 0.0.2, 0.0.1 [master
repo]
将 #import "DKTabPageViewController.h"
添加到将使用它的类的顶部。
NSMutableArray *items = [NSMutableArray arrayWithCapacity:5];
for (int i = 0; i < 5; i++) {
TableViewController *vc = [TableViewController new];
DKTabPageItem *item = [DKTabPageViewControllerItem tabPageItemWithTitle:[NSString stringWithFormat:@"Tab %d" ,i]
viewController:vc];
[items addObject:item];
}
DKTabPageViewController *tabPageViewController = [[DKTabPageViewController alloc] initWithItems:items];
[self addChildViewController:tabPageViewController];
[self.view addSubview:tabPageViewController.view];
@property (nonatomic, assign) NSInteger selectedIndex;
@property (nonatomic, readonly) UIViewController *selectedViewController;
/**
* Whether show the Tab Bar. Defaults to YES.
*/
@property (nonatomic, assign) BOOL showTabPageBar;
/**
* Add additional scroll area around content when contentViewController of view is UIScrollview of subclasses.
*/
@property (nonatomic, assign) UIEdgeInsets contentInsets;
/**
* Whether allow scroll gestures. Defaults to YES.
*/
@property (nonatomic, assign) BOOL gestureScrollEnabled;
/**
* The block to be executed on the page changed.
*/
@property (nonatomic, copy) void (^pageChangedBlock)(NSInteger selectedIndex);
/**
* Height of the tab bar. Defautls to 40.
*/
@property (nonatomic, assign) CGFloat tabBarHeight UI_APPEARANCE_SELECTOR;
/**
* Height of the selected indicator. Defaults to 3.
*/
@property (nonatomic, assign) CGFloat selectedIndicatorHeight UI_APPEARANCE_SELECTOR;
/**
* Color of the selected indicator. Defaults to an orange-red color.
*/
@property (nonatomic, copy) UIColor *selectedIndicatorColor UI_APPEARANCE_SELECTOR;
/**
* Font of the tab bar. Defautls to [UIFont systemFontOfSize:14].
*/
@property (nonatomic, strong) UIFont *titleFont UI_APPEARANCE_SELECTOR;
@property (nonatomic, copy) UIColor *titleColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, copy) UIColor *selectedTitleColor UI_APPEARANCE_SELECTOR;
/**
* Color of the 1 point shadow underline. Defaults to a gray color.
*/
@property (nonatomic, copy) UIColor *shadowColor UI_APPEARANCE_SELECTOR;
/**
* The selection indicator is draw on bottom of the tab bar.
*/
@property (nonatomic, strong) UIView *selectionIndicatorView;
[tabPageViewController setTabPageBarAnimationBlock:^(DKTabPageViewController *weakTabPageViewController, UIButton *fromButton, UIButton *toButton, CGFloat progress) {
// animated font
CGFloat pointSize = weakTabPageViewController.tabPageBar.titleFont.pointSize;
CGFloat selectedPointSize = 18;
fromButton.titleLabel.font = [UIFont systemFontOfSize:pointSize + (selectedPointSize - pointSize) * (1 - progress)];
toButton.titleLabel.font = [UIFont systemFontOfSize:pointSize + (selectedPointSize - pointSize) * progress];
// animated text color
CGFloat red, green, blue;
[weakTabPageViewController.tabPageBar.titleColor getRed:&red green:&green blue:&blue alpha:NULL];
CGFloat selectedRed, selectedGreen, selectedBlue;
[weakTabPageViewController.tabPageBar.selectedTitleColor getRed:&selectedRed green:&selectedGreen blue:&selectedBlue alpha:NULL];
[fromButton setTitleColor:[UIColor colorWithRed:red + (selectedRed - red) * (1 - progress)
green:green + (selectedGreen - green) * (1 - progress)
blue: blue + (selectedBlue - blue) * (1 - progress)
alpha:1] forState:UIControlStateSelected];
[toButton setTitleColor:[UIColor colorWithRed:red + (selectedRed - red) * progress
green:green + (selectedGreen - green) * progress
blue:blue + (selectedBlue - blue) * progress
alpha:1] forState:UIControlStateNormal];
}];
感谢您的贡献!Tate Johnson Matthew Ryan
本代码以 MIT 许可证条款和条件发布。