iOS 标签视图集合

Github传送门:github.com/JonHory/JHT…git

演示

V1.0

V1.1

demo里面写了如何展现相同宽度的标签。github

使用

  • 初始化JHTagView布局

    1 self.tagView = [[JHTagView alloc]initWithFrame:CGRectMake(0, 0, SCREEN.width - 60, 200)]code

    使用initWithFrame而不是init,是由于内部须要获取视图的最大宽度。orm

    2 配置一些属性cdn

配置按钮样式信息
normarlBackColor 正常背景颜色
normalTitleColor 正常文字颜色
normalBorderColor 正常边框颜色
selectedBackColor 选中背景颜色
selectedTitleColor 选中文字颜色

[self.tagView configWithNormalBackColor:[UIColor whiteColor] normalTitleColor:[UIColor blackColor] normalBorderColor:[UIColor redColor] AndSelectedBackColor:[UIColor orangeColor] selectedTitleColor:[UIColor whiteColor]];blog

配置布局样式
maxWidth 视图最大宽度
margin 按钮间距
isEnable 按钮是否可点击
borderWidth 边线宽
cornerRadius 圆角

[self.tagView configMaxWidth:self.tagView.bounds.size.width margin:10 buttonIsEnable:YES borderWidth:0.5 cornerRadius:4];get

3 先计算好高度it

CGFloat height = [self.tagView getMaxHeightWithModels:self.tagModels];io

4 赋值

self.tagView.tagModels = self.tagModels;

5 重置视图高度,用frame或者约束均可以

self.tagView.frame = CGRectMake(0, 0, SCREEN.width - 60, height);

6 完成✅

扩展性

按着demo中的思路,还能够继续深刻扩展到定义每一个标签的背景颜色/文字颜色等任意属性。

关于我

  • 若是在使用过程当中遇到问题,或者想要与我分享jonhory@163.com
  • 固然,欢迎在下面留言交流,若是有什么不爽的地方能够说出来,我会第一时间回复您。
相关文章
相关标签/搜索