JTScrollTitleViewController 1.2.1

JTScrollTitleViewController 1.2.1

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2019年4月

Jorton HUANG维护。



  • Jorton HUANG

Version Issues License Platform

JTScrollTitleViewController

获取一个带有可滚动标题栏的视图控制器

作者邮箱:[email protected]

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理器。

您可以使用以下命令安装它

$ gem install cocoapods

要使用 CocoaPods 将 JTScrollTitleViewController 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

pod 'JTScrollTitleViewController'

然后运行以下命令

$ pod install

导入到项目中

导入pod时,您应该添加字符串

  • 针对Obj-c项目
   #import "JTScrollTitleViewController.h"
  • 针对Swift项目
  import JTScrollTitleViewController

评论API

JTScrollTitleViewController.h

@interface JTScrollTitleViewController : UIViewController

@property(assign, nonatomic) NSInteger threshold;// default is 0 (3 or 4 depending on screen width)

@property(strong, nonatomic) UIColor *titleViewBgColor;// default is nil (Grey)
@property(assign, nonatomic) NSInteger titleViewHeight;// default is 36

@property(strong, nonatomic) UIColor *barViewColor;// default is nil (Orange)
@property(assign, nonatomic) CGFloat barHeight;// default is 3 must less than titleViewHeight
@property(assign, nonatomic) CGFloat barViewRate; // default is 0.7

@property(strong, nonatomic) UIFont *labelFont;// default is nil [UIFont systemFontOfSize:13]
@property(strong, nonatomic) UIColor *selectedlabelColor;// default is nil (Dark gray)
@property(strong, nonatomic) UIColor *unselectedlabelColor;// default is nil (Light gray)
@property(assign, nonatomic) CGFloat labelScaleRate;// default is 0.1

@property(assign, nonatomic) BOOL disallowContentScroll;//default is NO


/**
 Initializes an `JTScrollTitleViewController` object with similar child view controllers.
 
 @param titles The titles showed in the top scroll bar.
 @param initialization The initialization defined in the block used to initialize child view controllers with their indexes
 
 @return The newly-initialized scroll title view controller
 */
+ (instancetype)scrollTitleViewControllerWithTitles:(NSArray *)titles withInitializationForChildVCs:( UIViewController* (^)(NSInteger index)) initialization;

/**
 Initializes an `JTScrollTitleViewController` object with different child view controllers.
 
 @param viewControllers The viewControllers which will become child view controllers of this scroll title view controller
 
 @return The newly-initialized scroll title view controller
 */
+ (instancetype)scrollTitleViewControllerWithChildVCs:(NSArray *) viewControllers;

@end

如何使用

请查看示例。

示例

从JTScrollTitleViewController创建一个子类

#import "JTScrollTitleViewController.h"

@interface JTSimilarHomeViewController : JTScrollTitleViewController

@end

对于类似的子视图控制器

// Only 3 titles Fixed Title
// threshold default is 0 (3 or 4 depending on screen width)
// ScreenWidth < 350 ? 3 : 4
    
NSArray *array = @[@"Title1",@"Title2",@"Title3"];
    
JTSimilarHomeViewController *vc = [JTSimilarHomeViewController scrollTitleViewControllerWithTitles:array withInitializationForChildVCs:^UIViewController *(NSInteger index) {
        JTSimilarSingleViewController *svc = [[JTSimilarSingleViewController alloc]initWithStyle:UITableViewStylePlain];
        svc.title = array[index];
        return svc;
}];
    
[self.navigationController pushViewController:vc animated:YES];

对于不同的子视图控制器

// Two different types of View Controller(Normal and Table view)
// 6(more than 3 or 4) child view controllers, so the titles can be scrolled.
    
JTDifferentSingleViewController *vc1 = [self.storyboard instantiateViewControllerWithIdentifier:@"DifferentSingleViewController"];
vc1.title = @"Normal1";
    
JTSimilarSingleViewController *svc1 = [[JTSimilarSingleViewController alloc]initWithStyle:UITableViewStylePlain];
svc1.title = @"TableView1";
    
JTDifferentSingleViewController *vc2 = [self.storyboard instantiateViewControllerWithIdentifier:@"DifferentSingleViewController"];
vc2.title = @"Normal2";
    
JTSimilarSingleViewController *svc2 = [[JTSimilarSingleViewController alloc]initWithStyle:UITableViewStylePlain];
svc2.title = @"TableView2";
    
JTDifferentSingleViewController *vc3 =  [self.storyboard instantiateViewControllerWithIdentifier:@"DifferentSingleViewController"];
vc3.title = @"Normal3";
    
JTSimilarSingleViewController *svc3 = [[JTSimilarSingleViewController alloc]initWithStyle:UITableViewStylePlain];
svc3.title = @"TableView3";
    
    
JTDifferentHomeViewController *vc = [JTDifferentHomeViewController scrollTitleViewControllerWithChildVCs:@[vc1,svc1,vc2,svc2,vc3,svc3]];
    
vc.titleViewBgColor = [UIColor cyanColor];
vc.titleViewHeight = 44;
    
vc.barViewColor = [UIColor redColor];
vc.barHeight = 5;
vc.barViewRate = 0.3;
    
vc.labelFont = [UIFont systemFontOfSize:15];
vc.selectedlabelColor = [UIColor redColor];
vc.unselectedlabelColor = [UIColor lightGrayColor];
vc.labelScaleRate = 0.2;
    
[self.navigationController pushViewController:vc animated:YES];