iOS适配iOS进阶指南iOS 开发

【干货】每个APP都用得上的SegmentView(二)

2018-08-23  本文已影响82人  开源者联盟
JXCategoryView.png

腾讯新闻今日头条、QQ音乐、网易云音乐、京东、爱奇艺、淘宝、天猫、简书、微博等所有主流APP分类切换滚动视图

与其他的同类三方库对比的优点:

这篇文章主要讲解新增内容,更多基础内容点击这里查看上一篇文章

Github地址

下载源码,一睹为快!地址:JXCategoryView

新增效果预览

说明 Gif
QQ黏性红点 QQBall.gif
三角形底部 TriangleBottom.gif
三角形顶部 TriangleTop.gif
文字遮罩(无背景视图) TitleMaskNoBackgroundView.gif
背景指示图 BackgroundImageView.gif
矩形指示图 Rectangle.gif
自定义cell-红点 CellRedDot.gif
自定义cell-背景色渐变 CellBackgroundColorGradient.gif
混合使用 Mixed.gif
嵌套使用 Nest.gif
自定义cell示例-多行+富文本 AttributeView.gif
自定义Indicator示例-点线 IndicatorCustomizeGuide.gif

结构图

JXCategoryViewStructure.png

指示器样式自定义

仓库自带:JXCategoryIndicatorLineView、JXCategoryIndicatorTriangleView、JXCategoryIndicatorImageView、JXCategoryIndicatorBackgroundView、JXCategoryIndicatorBallView

主要实现的方法:

具体实例:参考demo工程里面的JXCategoryIndicatorDotLineView

Cell子类化注意事项

仓库自带:JXCategoryTitleView、JXCategoryTitleImageView、JXCategoryNumberView、JXCategoryDotView、JXCategoryImageView

主要实现的方法:

具体实例:参考demo工程里面的JXCategoryTitleAttributeView

继承提示

POP说明

通过将指示器的行为抽象出来,再通过JXCategoryIndicatorProtocol协议进行约束。这样指示器效果就可以无限扩展,为所欲为的添加指示器了,不再受上一个版本继承的束缚了。更多POP内容,推荐喵神的文章面向协议编程与 Cocoa 的邂逅

代码示例

JXCategoryTitleView *categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 100, 300, 30)];
categoryView.titles = @[@"主题一", @"主题二"];

JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
lineView.indicatorLineWidth = JXCategoryViewAutomaticDimension;  
lineView.indicatorLineViewHeight = 3;
lineView.indicatorLineViewCornerRadius = JXCategoryViewAutomaticDimension;
lineView.indicatorLineViewColor = [UIColor redColor];
categoryView.indicators = @[lineView];
[self.view addSubview:categoryView];
JXCategoryTitleView *categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 100, 300, 30)];
categoryView.titles = @[@"主题一", @"主题二"];

JXCategoryIndicatorTriangleView *triangleView = [[JXCategoryIndicatorTriangleView alloc] init];
triangleView.triangleViewSize = CGSizeMake(14, 10);
triangleView.triangleViewColor = [UIColor redColor];
triangleView.componentPosition = JXCategoryComponentPosition_Bottom;
//triangleView.componentPosition = JXCategoryComponentPosition_Top; 放在顶部
categoryView.indicators = @[triangleView];
[self.view addSubview:categoryView];
JXCategoryTitleView *categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 100, 300, 30)];
categoryView.titles = @[@"主题一", @"主题二"];

JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
//椭圆形
backgroundView.backgroundViewHeight = 20;
backgroundView.backgroundViewCornerRadius = JXCategoryViewAutomaticDimension;
//长方形
//backgroundView.backgroundViewHeight = JXCategoryViewAutomaticDimension;
//backgroundView.backgroundViewCornerRadius = 0;
categoryView.indicators = @[backgroundView];
[self.view addSubview:categoryView];
JXCategoryTitleView *categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 100, 300, 30)];
categoryView.titles = @[@"主题一", @"主题二"];

JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
backgroundView.backgroundViewHeight = 20;
categoryView.indicators = @[backgroundView, lineView];
[self.view addSubview:categoryView];

Github地址

下载源码,一睹为快!地址:JXCategoryView

补充

该仓库保持随时更新,对于主流新的分类选择效果会第一时间支持。使用过程中,有任何建议或问题,可以通过以下方式联系我:
邮箱:317437084@qq.com
QQ群: 112440151

上一篇下一篇

猜你喜欢

热点阅读