@@ -30,14 +30,44 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
30
30
internal lazy var views : Dictionary < String , AnyObject > = Dictionary < String , AnyObject > ( )
31
31
32
32
/**
33
- :name: verticalSpace
33
+ :name: verticalImageViewSpace
34
34
*/
35
- public var verticalSpace : CGFloat = MaterialTheme . verticalSpace
35
+ public var verticalImageViewSpace : CGFloat = 0
36
36
37
37
/**
38
- :name: horizontalSpace
38
+ :name: horizontalImageViewSpace
39
39
*/
40
- public var horizontalSpace : CGFloat = MaterialTheme . horizontalSpace
40
+ public var horizontalImageViewSpace : CGFloat = 0
41
+
42
+ /**
43
+ :name: verticalTitleLabelSpace
44
+ */
45
+ public var verticalTitleLabelSpace : CGFloat = MaterialTheme . verticalSpace
46
+
47
+ /**
48
+ :name: horizontalTitleLabelSpace
49
+ */
50
+ public var horizontalTitleLabelSpace : CGFloat = MaterialTheme . horizontalSpace
51
+
52
+ /**
53
+ :name: verticalDetailLabelSpace
54
+ */
55
+ public var verticalDetailLabelSpace : CGFloat = MaterialTheme . verticalSpace
56
+
57
+ /**
58
+ :name: horizontalDetailLabelSpace
59
+ */
60
+ public var horizontalDetailLabelSpace : CGFloat = MaterialTheme . horizontalSpace
61
+
62
+ /**
63
+ :name: verticalButtonSpace
64
+ */
65
+ public var verticalButtonSpace : CGFloat = MaterialTheme . verticalSpace
66
+
67
+ /**
68
+ :name: horizontalButtonSpace
69
+ */
70
+ public var horizontalButtonSpace : CGFloat = MaterialTheme . horizontalSpace
41
71
42
72
/**
43
73
:name: shadow
@@ -288,18 +318,24 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
288
318
289
319
// image
290
320
if nil != imageViewContainer && nil != imageView {
321
+ // clear for updated constraints
322
+ imageViewContainer!. removeConstraints ( imageViewContainer!. constraints ( ) )
323
+
291
324
// container
292
325
layoutConstraints += Layout . constraint ( " H:|[imageViewContainer]| " , options: nil , metrics: nil , views: [ " imageViewContainer " : imageViewContainer!] )
293
326
verticalFormat += " [imageViewContainer] "
294
327
views [ " imageViewContainer " ] = imageViewContainer!
295
328
296
329
// text
297
- imageViewContainer!. addConstraints ( Layout . constraint ( " H:|[imageView]| " , options: nil , metrics: nil , views: [ " imageView " : imageView!] ) )
298
- imageViewContainer!. addConstraints ( Layout . constraint ( " V:|[imageView(maximumImageViewHeight)]| " , options: nil , metrics: [ " maximumImageViewHeight " : maximumImageViewHeight] , views: [ " imageView " : imageView!] ) )
330
+ imageViewContainer!. addConstraints ( Layout . constraint ( " H:|-(horizontalImageViewSpace)- [imageView]-(horizontalImageViewSpace)- | " , options: nil , metrics: [ " horizontalImageViewSpace " : horizontalImageViewSpace ] , views: [ " imageView " : imageView!] ) )
331
+ imageViewContainer!. addConstraints ( Layout . constraint ( " V:|-(verticalImageViewSpace)- [imageView(maximumImageViewHeight)]-(verticalImageViewSpace)- | " , options: nil , metrics: [ " verticalImageViewSpace " : verticalImageViewSpace , " maximumImageViewHeight " : maximumImageViewHeight] , views: [ " imageView " : imageView!] ) )
299
332
}
300
333
301
334
// title
302
335
if nil != titleLabelContainer && nil != titleLabel {
336
+ // clear for updated constraints
337
+ titleLabelContainer!. removeConstraints ( titleLabelContainer!. constraints ( ) )
338
+
303
339
if nil == imageView {
304
340
// container
305
341
layoutConstraints += Layout . constraint ( " H:|[titleLabelContainer]| " , options: nil , metrics: nil , views: [ " titleLabelContainer " : titleLabelContainer!] )
@@ -313,24 +349,30 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
313
349
314
350
// common text
315
351
Layout . height ( titleLabelContainer!, child: titleLabel!, height: 1.5 * titleLabel!. font. pointSize)
316
- Layout . expandToParentVerticallyWithPad ( titleLabelContainer!, child: titleLabel!, top: verticalSpace , bottom: verticalSpace )
317
- Layout . expandToParentHorizontallyWithPad ( titleLabelContainer!, child: titleLabel!, left: horizontalSpace , right: horizontalSpace )
352
+ Layout . expandToParentVerticallyWithPad ( titleLabelContainer!, child: titleLabel!, top: verticalTitleLabelSpace , bottom: verticalTitleLabelSpace )
353
+ Layout . expandToParentHorizontallyWithPad ( titleLabelContainer!, child: titleLabel!, left: horizontalTitleLabelSpace , right: horizontalTitleLabelSpace )
318
354
}
319
355
320
356
// detail
321
357
if nil != detailLabelContainer && nil != detailLabel {
358
+ // clear for updated constraints
359
+ detailLabelContainer!. removeConstraints ( detailLabelContainer!. constraints ( ) )
360
+
322
361
// container
323
362
layoutConstraints += Layout . constraint ( " H:|[detailLabelContainer]| " , options: nil , metrics: nil , views: [ " detailLabelContainer " : detailLabelContainer!] )
324
363
verticalFormat += " [detailLabelContainer] "
325
364
views [ " detailLabelContainer " ] = detailLabelContainer!
326
365
327
366
// text
328
- Layout . expandToParentHorizontallyWithPad ( detailLabelContainer!, child: detailLabel!, left: horizontalSpace , right: horizontalSpace )
329
- detailLabelContainer!. addConstraints ( Layout . constraint ( " V:|-(verticalSpace )-[detailLabel(<=maximumDetailLabelHeight)]-(verticalSpace )-| " , options: nil , metrics: [ " verticalSpace " : verticalSpace , " maximumDetailLabelHeight " : maximumDetailLabelHeight] , views: [ " detailLabel " : detailLabel!] ) )
367
+ Layout . expandToParentHorizontallyWithPad ( detailLabelContainer!, child: detailLabel!, left: horizontalDetailLabelSpace , right: horizontalDetailLabelSpace )
368
+ detailLabelContainer!. addConstraints ( Layout . constraint ( " V:|-(verticalDetailLabelSpace )-[detailLabel(<=maximumDetailLabelHeight)]-(verticalDetailLabelSpace )-| " , options: nil , metrics: [ " verticalDetailLabelSpace " : verticalDetailLabelSpace , " maximumDetailLabelHeight " : maximumDetailLabelHeight] , views: [ " detailLabel " : detailLabel!] ) )
330
369
}
331
370
332
371
// buttons
333
372
if nil != buttonsContainer && ( nil != leftButtons || nil != rightButtons) {
373
+ // clear for updated constraints
374
+ buttonsContainer!. removeConstraints ( buttonsContainer!. constraints ( ) )
375
+
334
376
// divider
335
377
if nil != divider {
336
378
layoutConstraints += Layout . constraint ( " H:|[divider]| " , options: nil , metrics: nil , views: [ " divider " : divider!] )
@@ -351,10 +393,10 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
351
393
let button : MaterialButton = leftButtons![ i]
352
394
buttonsContainer!. addSubview ( button)
353
395
buttonViews [ " button \( i) " ] = button
354
- horizontalFormat += " -(horizontalSpace )-[button \( i) ] "
355
- Layout . expandToParentVerticallyWithPad ( buttonsContainer!, child: button, top: verticalSpace , bottom: verticalSpace )
396
+ horizontalFormat += " -(horizontalButtonSpace )-[button \( i) ] "
397
+ Layout . expandToParentVerticallyWithPad ( buttonsContainer!, child: button, top: verticalButtonSpace , bottom: verticalButtonSpace )
356
398
}
357
- buttonsContainer!. addConstraints ( Layout . constraint ( horizontalFormat, options: nil , metrics: [ " horizontalSpace " : horizontalSpace ] , views: buttonViews) )
399
+ buttonsContainer!. addConstraints ( Layout . constraint ( horizontalFormat, options: nil , metrics: [ " horizontalButtonSpace " : horizontalButtonSpace ] , views: buttonViews) )
358
400
}
359
401
360
402
// rightButtons
@@ -365,10 +407,10 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
365
407
let button : MaterialButton = rightButtons![ i]
366
408
buttonsContainer!. addSubview ( button)
367
409
buttonViews [ " button \( i) " ] = button
368
- horizontalFormat += " [button \( i) ]-(horizontalSpace )- "
369
- Layout . expandToParentVerticallyWithPad ( buttonsContainer!, child: button, top: verticalSpace , bottom: verticalSpace )
410
+ horizontalFormat += " [button \( i) ]-(horizontalButtonSpace )- "
411
+ Layout . expandToParentVerticallyWithPad ( buttonsContainer!, child: button, top: verticalButtonSpace , bottom: verticalButtonSpace )
370
412
}
371
- buttonsContainer!. addConstraints ( Layout . constraint ( horizontalFormat + " | " , options: nil , metrics: [ " horizontalSpace " : horizontalSpace ] , views: buttonViews) )
413
+ buttonsContainer!. addConstraints ( Layout . constraint ( horizontalFormat + " | " , options: nil , metrics: [ " horizontalButtonSpace " : horizontalButtonSpace ] , views: buttonViews) )
372
414
}
373
415
}
374
416
0 commit comments