Commit 2eafa14f008ac2546248078d8813f8a6ba321bd0

Authored by “张旭”
1 parent 1b01b94b

已认证-卡片keylbl 2个字时两端对齐

metaCode/Classes/Main/HomePage/View/VerticalViews/MainView/CNIDCardView.swift
@@ -73,39 +73,6 @@ class CNIDCardView: UIView{ @@ -73,39 +73,6 @@ class CNIDCardView: UIView{
73 if respStatue == .success { 73 if respStatue == .success {
74 let cardArray = result as! NSMutableArray 74 let cardArray = result as! NSMutableArray
75 self.cardUIWithArray(cardArr: cardArray) 75 self.cardUIWithArray(cardArr: cardArray)
76 -  
77 -// if cardArray.count > 0{  
78 -// for i in (0..<cardArray.count){  
79 -// let idCardModel = cardArray[i] as! MineStandInfoModel  
80 -// let siBianGap:CGFloat = 17  
81 -// let labelsGap:CGFloat = 10  
82 -//  
83 -// let keyLabel = UILabel.init()  
84 -// keyLabel.textColor = HexColor(_idModel?.backgroundColor ?? "")  
85 -// keyLabel.textAlignment = .left  
86 -// keyLabel.font = Font(15)  
87 -// keyLabel.backgroundColor = .clear  
88 -// keyLabel.text = idCardModel.name ?? ""  
89 -// keyLabel.frame = CGRect(x: siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: 70, height: 21)  
90 -// keyLabel.adjustsFontSizeToFitWidth = true  
91 -// keyLabel.tag = 10000+i  
92 -// self.addSubview(keyLabel)  
93 -//  
94 -// let valueLabel = UILabel.init()  
95 -// valueLabel.textColor = HexColor(_idModel?.backgroundColor ?? "")  
96 -// valueLabel.textAlignment = .left  
97 -// valueLabel.font = Font(15)  
98 -// valueLabel.backgroundColor = .clear  
99 -// valueLabel.text = idCardModel.userInfo ?? ""  
100 -// valueLabel.frame = CGRect(x: keyLabel.right+labelsGap+siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: self.width-keyLabel.right-labelsGap-siBianGap-5, height: 21)  
101 -// valueLabel.adjustsFontSizeToFitWidth = true  
102 -// valueLabel.tag = 20000+i  
103 -// self.addSubview(valueLabel)  
104 -//  
105 -// }  
106 -// }else{  
107 -// //没数据  
108 -// }  
109 } 76 }
110 } 77 }
111 } 78 }
@@ -116,6 +83,24 @@ class CNIDCardView: UIView{ @@ -116,6 +83,24 @@ class CNIDCardView: UIView{
116 view.removeFromSuperview() 83 view.removeFromSuperview()
117 } 84 }
118 } 85 }
  86 +
  87 + var maxLblWidth:CGFloat = 0
  88 + for model in cardArr {
  89 + let idCardMdl = model as! MineStandInfoModel
  90 +
  91 + let keyLabel = UILabel.init()
  92 + keyLabel.textAlignment = .left
  93 + keyLabel.font = Font(15)
  94 + keyLabel.backgroundColor = .clear
  95 + keyLabel.text = idCardMdl.name ?? ""
  96 + keyLabel.sizeToFit()
  97 + let lblWidth = keyLabel.bounds.size.width
  98 + if maxLblWidth < lblWidth{
  99 + //更新更大的label宽度
  100 + maxLblWidth = lblWidth
  101 + }
  102 + }
  103 +
119 let cardArray = NSMutableArray(array: cardArr) 104 let cardArray = NSMutableArray(array: cardArr)
120 if cardArray.count > 0{ 105 if cardArray.count > 0{
121 for i in (0..<cardArray.count){ 106 for i in (0..<cardArray.count){
@@ -123,16 +108,48 @@ class CNIDCardView: UIView{ @@ -123,16 +108,48 @@ class CNIDCardView: UIView{
123 let siBianGap:CGFloat = 17 108 let siBianGap:CGFloat = 17
124 let labelsGap:CGFloat = 10 109 let labelsGap:CGFloat = 10
125 110
126 - let keyLabel = UILabel.init()  
127 - keyLabel.textColor = HexColor(_idModel?.backgroundColor ?? "")  
128 - keyLabel.textAlignment = .left  
129 - keyLabel.font = Font(15)  
130 - keyLabel.backgroundColor = .clear  
131 - keyLabel.text = idCardModel.name ?? ""  
132 - keyLabel.frame = CGRect(x: siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: 70, height: 21)  
133 - keyLabel.adjustsFontSizeToFitWidth = true  
134 - keyLabel.tag = 10000+i  
135 - self.addSubview(keyLabel) 111 + var keyLblRight:CGFloat = 0
  112 + if idCardModel.name?.count == 2{
  113 + //2个字特殊处理,2边对齐
  114 + let keyLabel1 = UILabel.init()
  115 + keyLabel1.textColor = HexColor(_idModel?.backgroundColor ?? "")
  116 + keyLabel1.textAlignment = .left
  117 + keyLabel1.font = Font(15)
  118 + keyLabel1.backgroundColor = .clear
  119 + keyLabel1.text = idCardModel.name?.subString(start: 0, length: 1) ?? ""
  120 + keyLabel1.sizeToFit()
  121 + keyLabel1.frame = CGRect(x: siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: maxLblWidth, height: keyLabel1.bounds.size.height)
  122 + keyLabel1.adjustsFontSizeToFitWidth = true
  123 + keyLabel1.tag = 10000+i+100
  124 + self.addSubview(keyLabel1)
  125 +
  126 + let keyLabel2 = UILabel.init()
  127 + keyLabel2.textColor = HexColor(_idModel?.backgroundColor ?? "")
  128 + keyLabel2.textAlignment = .right
  129 + keyLabel2.font = Font(15)
  130 + keyLabel2.backgroundColor = .clear
  131 + keyLabel2.text = idCardModel.name?.subString(start: 1, length: 1) ?? ""
  132 + keyLabel2.sizeToFit()
  133 + keyLabel2.frame = CGRect(x: siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: maxLblWidth, height: keyLabel1.bounds.size.height)
  134 + keyLabel2.adjustsFontSizeToFitWidth = true
  135 + keyLabel2.tag = 10000+i+200
  136 + self.addSubview(keyLabel2)
  137 + keyLblRight = keyLabel2.right
  138 + }else{
  139 + //其他字数左对齐
  140 + let keyLabel = UILabel.init()
  141 + keyLabel.textColor = HexColor(_idModel?.backgroundColor ?? "")
  142 + keyLabel.textAlignment = .left
  143 + keyLabel.font = Font(15)
  144 + keyLabel.backgroundColor = .clear
  145 + keyLabel.text = idCardModel.name ?? ""
  146 + keyLabel.sizeToFit()
  147 + keyLabel.frame = CGRect(x: siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: keyLabel.bounds.size.width, height: keyLabel.bounds.size.height)
  148 + keyLabel.adjustsFontSizeToFitWidth = true
  149 + keyLabel.tag = 10000+i
  150 + self.addSubview(keyLabel)
  151 + keyLblRight = keyLabel.right
  152 + }
136 153
137 let valueLabel = UILabel.init() 154 let valueLabel = UILabel.init()
138 valueLabel.textColor = HexColor(_idModel?.backgroundColor ?? "") 155 valueLabel.textColor = HexColor(_idModel?.backgroundColor ?? "")
@@ -140,7 +157,7 @@ class CNIDCardView: UIView{ @@ -140,7 +157,7 @@ class CNIDCardView: UIView{
140 valueLabel.font = Font(15) 157 valueLabel.font = Font(15)
141 valueLabel.backgroundColor = .clear 158 valueLabel.backgroundColor = .clear
142 valueLabel.text = idCardModel.userInfo ?? "" 159 valueLabel.text = idCardModel.userInfo ?? ""
143 - valueLabel.frame = CGRect(x: keyLabel.right+labelsGap+siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: self.width-keyLabel.right-labelsGap-siBianGap-5, height: 21) 160 + valueLabel.frame = CGRect(x: keyLblRight+labelsGap+siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: self.width-keyLblRight-labelsGap-siBianGap-5, height: 21)
144 valueLabel.adjustsFontSizeToFitWidth = true 161 valueLabel.adjustsFontSizeToFitWidth = true
145 valueLabel.tag = 20000+i 162 valueLabel.tag = 20000+i
146 self.addSubview(valueLabel) 163 self.addSubview(valueLabel)
metaCode/Classes/Main/HomePage/View/VerticalViews/MainView/CNMainView.swift
@@ -279,7 +279,6 @@ class CNFrontMainView : UIView{ @@ -279,7 +279,6 @@ class CNFrontMainView : UIView{
279 return downMoreGIF 279 return downMoreGIF
280 }() 280 }()
281 281
282 - // MARK: - 已认证  
283 ///已认证-前置视图卡片容器 282 ///已认证-前置视图卡片容器
284 lazy var frontCardContentView : UIView = { 283 lazy var frontCardContentView : UIView = {
285 284