Github传送门:github.com/JonHory/JHT…git
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 完成✅