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
  • 固然,歡迎在下面留言交流,若是有什麼不爽的地方能夠說出來,我會第一時間回覆您。
相關文章
相關標籤/搜索