iOS开发指南控件类@IT·互联网

iOS 横向滚动菜单组件

2017-05-13  本文已影响383人  波儿菜

先上效果图:

YBLevelListGif.gif

优势

该框架的解决的核心问题就是顶部滚动菜单的高度自定义。
顶部的标题view,支持富文本,支持图片,支持选中状态和未选中状态的动态自定义,性能稳定良好

用法

该框架已添加cocopods支持:
pod 'YBLevelList', '~> 1.0.0'

代码如下:

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //* 初始化所有子控制器(子控制器里面的约束最好用layout写)
    UIViewController *vc0 = [UIViewController new];
    UIViewController *vc1 = [UIViewController new];
    UIViewController *vc2 = [UIViewController new];
    UIViewController *vc3 = [UIViewController new];
    
    vc0.view.backgroundColor = [UIColor redColor];
    vc1.view.backgroundColor = [UIColor orangeColor];
    vc2.view.backgroundColor = [UIColor lightGrayColor];
    vc3.view.backgroundColor = [UIColor cyanColor];
    
    
    
    //* 这里是一个用于测试的富文本
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"人数(99+)" attributes:nil];
    [attr addAttribute:NSForegroundColorAttributeName value:[UIColor darkTextColor] range:NSMakeRange(0, 2)];
    [attr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, 2)];
    [attr addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(2, 5)];
    [attr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:10] range:NSMakeRange(2, 5)];
    
//* 配置titleview的model(YBLevelListConfigModel是配置顶部标题view的类,里面有很多自定义的配置,可下载下来查看)
    YBLevelListConfigModel *model = [YBLevelListConfigModel new];
    //正常情况下的配置
    model.titleArr = @[@"标题1", @"标题2标题2", @"标题3标题3标题3", @"标题4标题4标题4标题4"];
    model.imageInfoArr = @[@"study_detail_0", @"study_detail_1", @"study_detail_2", @"study_detail_3"];
    //选中状态下的配置 (根据需求考虑)
    model.titleSelectedArr = @[attr];
    model.imageInfoSelectedArr = @[@"study_detail_3", @"study_detail_2", @"study_detail_1", @"study_detail_0"];
    
    
    
    //初始化(有更简洁的初始化方式)
    [self initializeWithControllers:@[vc0, vc1, vc2, vc3]
               titleViewConfigModel:model
                     titleViewFrame:CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, 44)
                   contentViewFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64)];
    
}

可到github下载DEMO ,地址:
https://github.com/indulgeIn/YBLevelList

上一篇下一篇

猜你喜欢

热点阅读