今天写了个二级联动,并且可以弹出一个可拖拽的视图,允许拖拽标题,拖拽完成自动交换布局,而且标题宽度自动适配,允许标题宽度不一致,添加随着滚动颜色渐变,文字大小渐变,下划线大小位置渐变效果,样式可以选择下划线和栅栏效果,直接上效果图
-
效果1
1.gif -
效果2
2.gif -
效果3
3.gif
而且使用简单
但是因为其中涉及到拖拽排序,所有标题数组希望是一个模型
你可以自定义一个模型,只需要继承自SegmentTitleModel就行,里面的title就是标题栏标题
代码如下
- (void)setSegmentView:(YWSegementStyle)segementStyle YWSegementIndicateStyle:(YWSegementIndicateStyle)segementIndicateStyle isShowSelectView:(BOOL)isShowSelectView{
NSMutableArray *mutArr = [NSMutableArray array];
NSMutableArray *titleArr = [NSMutableArray array];
NSArray *titles = @[@"精选",@"2018世界杯",@"明日之子",@"电影",@"电视剧",@"NBA",@"花样年华"];
for (int i = 0; i < 7; i++) {
YWDetailViewController *tabVC = [YWDetailViewController new];
tabVC.title = titles[i];
[mutArr addObject:tabVC];
SegmentTitleModel *model = [[SegmentTitleModel alloc]init];
model.title = titles[i];
[titleArr addObject:model];
}
YWSegmentView *segmentView = [[YWSegmentView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navigationController.navigationBar.frame), self.view.bounds.size.width, [UIScreen mainScreen].bounds.size.height - CGRectGetMaxY(self.navigationController.navigationBar.frame)) ViewControllersArr:[mutArr copy] TitleArr:titleArr TitleNormalSize:16 TitleSelectedSize:20 SegmentStyle:segementStyle ParentViewController:self ReturnIndexBlock:^(NSInteger index) {
NSLog(@"点击了%ld模块",(long)index);
}];
segmentView.yw_indicateStyle = segementIndicateStyle;
segmentView.isShowSelectView = isShowSelectView;
segmentView.isShowTitleBottomView = YES;
[self.view addSubview:segmentView];
}
感兴趣的可以看一下Demo
网友评论