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 完成✅