@@ -32,12 +32,12 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
32
32
/**
33
33
:name: verticalSpace
34
34
*/
35
- public var verticalSpace : CGFloat = 8
35
+ public var verticalSpace : CGFloat = MaterialTheme . verticalSpace
36
36
37
37
/**
38
38
:name: horizontalSpace
39
39
*/
40
- public var horizontalSpace : CGFloat = 8
40
+ public var horizontalSpace : CGFloat = MaterialTheme . horizontalSpace
41
41
42
42
/**
43
43
:name: titleLabelContainer
@@ -72,8 +72,9 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
72
72
t. setTranslatesAutoresizingMaskIntoConstraints ( false )
73
73
t. textColor = MaterialTheme . white. color
74
74
t. backgroundColor = MaterialTheme . clear. color
75
- t. font = Roboto . mediumWithSize ( 18 )
75
+ t. font = Roboto . medium
76
76
t. numberOfLines = 1
77
+ t. lineBreakMode = . ByTruncatingTail
77
78
prepareCard ( )
78
79
} else {
79
80
titleLabelContainer? . removeFromSuperview ( )
@@ -110,9 +111,9 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
110
111
l. setTranslatesAutoresizingMaskIntoConstraints ( false )
111
112
l. textColor = MaterialTheme . white. color
112
113
l. backgroundColor = MaterialTheme . clear. color
113
- l. font = Roboto . lightWithSize ( 16 )
114
+ l. font = Roboto . light
114
115
l. numberOfLines = 0
115
- l. lineBreakMode = . ByWordWrapping
116
+ l. lineBreakMode = . ByTruncatingTail
116
117
prepareCard ( )
117
118
} else {
118
119
detailLabelContainer? . removeFromSuperview ( )
@@ -161,7 +162,7 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
161
162
}
162
163
163
164
/**
164
- :name: rightButtons
165
+ :name: rightButtons
165
166
*/
166
167
public var rightButtons : Array < MaterialButton > ? {
167
168
didSet {
@@ -179,6 +180,39 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
179
180
}
180
181
}
181
182
183
+ /**
184
+ :name: init
185
+ */
186
+ public required init ( coder aDecoder: NSCoder ) {
187
+ super. init ( coder: aDecoder)
188
+ }
189
+
190
+ /**
191
+ :name: init
192
+ */
193
+ public convenience init ? ( titleLabel: UILabel ? = nil , detailLabel: UILabel ? = nil , divider: UIView ? = nil , leftButtons: Array < MaterialButton > ? = nil , rightButtons: Array < MaterialButton > ? = nil ) {
194
+ self . init ( frame: CGRectZero)
195
+ prepareProperties ( titleLabel, detailLabel: detailLabel, divider: divider, leftButtons: leftButtons, rightButtons: rightButtons)
196
+ }
197
+
198
+ /**
199
+ :name: init
200
+ */
201
+ public required init ( frame: CGRect ) {
202
+ super. init ( frame: CGRectZero)
203
+ }
204
+
205
+ //
206
+ // :name: prepareProperties
207
+ //
208
+ internal func prepareProperties( titleLabel: UILabel ? , detailLabel: UILabel ? , divider: UIView ? , leftButtons: Array < MaterialButton > ? , rightButtons: Array < MaterialButton > ? ) {
209
+ self . titleLabel = titleLabel
210
+ self . detailLabel = detailLabel
211
+ self . divider = divider
212
+ self . leftButtons = leftButtons
213
+ self . rightButtons = rightButtons
214
+ }
215
+
182
216
//
183
217
// :name: prepareView
184
218
//
@@ -208,9 +242,10 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
208
242
verticalFormat += " [titleLabelContainer] "
209
243
views [ " titleLabelContainer " ] = titleLabelContainer!
210
244
211
- // text
212
- titleLabelContainer!. addConstraints ( Layout . constraint ( " H:|-(horizontalSpace)-[titleLabel]-(horizontalSpace)-| " , options: nil , metrics: [ " horizontalSpace " : horizontalSpace] , views: [ " titleLabel " : titleLabel!] ) )
213
- titleLabelContainer!. addConstraints ( Layout . constraint ( " V:|-(verticalSpace)-[titleLabel(height)]-(verticalSpace)-| " , options: nil , metrics: [ " verticalSpace " : verticalSpace, " height " : titleLabel!. font. pointSize + verticalSpace] , views: [ " titleLabel " : titleLabel!] ) )
245
+ // common text
246
+ Layout . height ( titleLabelContainer!, child: titleLabel!, height: 1.5 * titleLabel!. font. pointSize)
247
+ Layout . expandToParentVerticallyWithPad ( titleLabelContainer!, child: titleLabel!, top: verticalSpace, bottom: verticalSpace)
248
+ Layout . expandToParentHorizontallyWithPad ( titleLabelContainer!, child: titleLabel!, left: horizontalSpace, right: horizontalSpace)
214
249
}
215
250
216
251
// detail
@@ -221,10 +256,11 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
221
256
views [ " detailLabelContainer " ] = detailLabelContainer!
222
257
223
258
// text
224
- detailLabelContainer! . addConstraints ( Layout . constraint ( " H:|-(horizontalSpace)-[detailLabel]-(horizontalSpace)-| " , options : nil , metrics : [ " horizontalSpace " : horizontalSpace ] , views : [ " detailLabel " : detailLabel! ] ) )
259
+ Layout . expandToParentHorizontallyWithPad ( detailLabelContainer! , child : detailLabel! , left : horizontalSpace, right : horizontalSpace )
225
260
detailLabelContainer!. addConstraints ( Layout . constraint ( " V:|-(verticalSpace)-[detailLabel(<=maximumDetailLabelHeight)]-(verticalSpace)-| " , options: nil , metrics: [ " verticalSpace " : verticalSpace, " maximumDetailLabelHeight " : maximumDetailLabelHeight] , views: [ " detailLabel " : detailLabel!] ) )
226
261
}
227
262
263
+ // buttons
228
264
if nil != buttonsContainer && ( nil != leftButtons || nil != rightButtons) {
229
265
// divider
230
266
if nil != divider {
@@ -247,7 +283,7 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
247
283
buttonsContainer!. addSubview ( button)
248
284
buttonViews [ " button \( i) " ] = button
249
285
horizontalFormat += " -(horizontalSpace)-[button \( i) ] "
250
- Layout . expandToParentVerticallyWithPad ( buttonsContainer!, child: button, top: horizontalSpace , bottom: verticalSpace)
286
+ Layout . expandToParentVerticallyWithPad ( buttonsContainer!, child: button, top: verticalSpace , bottom: verticalSpace)
251
287
}
252
288
buttonsContainer!. addConstraints ( Layout . constraint ( horizontalFormat, options: nil , metrics: [ " horizontalSpace " : horizontalSpace] , views: buttonViews) )
253
289
}
@@ -261,7 +297,7 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
261
297
buttonsContainer!. addSubview ( button)
262
298
buttonViews [ " button \( i) " ] = button
263
299
horizontalFormat += " [button \( i) ]-(horizontalSpace)- "
264
- Layout . expandToParentVerticallyWithPad ( buttonsContainer!, child: button, top: horizontalSpace , bottom: verticalSpace)
300
+ Layout . expandToParentVerticallyWithPad ( buttonsContainer!, child: button, top: verticalSpace , bottom: verticalSpace)
265
301
}
266
302
buttonsContainer!. addConstraints ( Layout . constraint ( horizontalFormat + " | " , options: nil , metrics: [ " horizontalSpace " : horizontalSpace] , views: buttonViews) )
267
303
}
0 commit comments