DKTabPageViewController 1.4.9

DKTabPageViewController 1.4.9

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最新发布2017年7月

Bannings 维护。



  • Bannings

GIF GIF GIF

顶部栏文本的自定义动画

GIF

顶部栏已隐藏

GIF

支持视觉效果。

GIF

概览

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日

  • 添加了对 iOS 6 的支持。

将要完成的工作

  • 添加从 xib(storyboard) 加载的支持。
  • 添加顶部栏可滚动的支持。

如何开始

$ 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" 添加到将使用它的类的顶部。

使用 DKTabPageItem 数组初始化 DKTabPageViewController。

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];

将 DKTabPageViewController 的视图添加为子视图

[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 许可证条款和条件发布。