Commit 9410474e by Daniel Dahan

card alignment fix prior to color additions

parent a2559db4
...@@ -42,12 +42,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -42,12 +42,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: titleLabelTopInset :name: titleLabelTopInset
*/ */
public var titleLabelTopInset: CGFloat = MaterialTheme.verticalInset public var titleLabelTopInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/** /**
:name: titleLabelBottomInset :name: titleLabelBottomInset
*/ */
public var titleLabelBottomInset: CGFloat = MaterialTheme.verticalInset public var titleLabelBottomInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/** /**
:name: titleLabelHorizontalInset :name: titleLabelHorizontalInset
...@@ -62,12 +70,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -62,12 +70,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: titleLabelLeftInset :name: titleLabelLeftInset
*/ */
public var titleLabelLeftInset: CGFloat = MaterialTheme.horizontalInset public var titleLabelLeftInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
prepareCard()
}
}
/** /**
:name: titleLabelRightInset :name: titleLabelRightInset
*/ */
public var titleLabelRightInset: CGFloat = MaterialTheme.horizontalInset public var titleLabelRightInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
prepareCard()
}
}
/** /**
:name: detailLabelVerticalInset :name: detailLabelVerticalInset
...@@ -82,12 +98,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -82,12 +98,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: detailLabelTopInset :name: detailLabelTopInset
*/ */
public var detailLabelTopInset: CGFloat = MaterialTheme.verticalInset public var detailLabelTopInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/** /**
:name: detailLabelBottomInset :name: detailLabelBottomInset
*/ */
public var detailLabelBottomInset: CGFloat = MaterialTheme.verticalInset public var detailLabelBottomInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/** /**
:name: detailLabelHorizontalInset :name: detailLabelHorizontalInset
...@@ -102,12 +126,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -102,12 +126,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: detailLabelLeftInset :name: detailLabelLeftInset
*/ */
public var detailLabelLeftInset: CGFloat = MaterialTheme.horizontalInset public var detailLabelLeftInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
prepareCard()
}
}
/** /**
:name: detailLabelRightInset :name: detailLabelRightInset
*/ */
public var detailLabelRightInset: CGFloat = MaterialTheme.horizontalInset public var detailLabelRightInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
prepareCard()
}
}
/** /**
:name: buttonVerticalInset :name: buttonVerticalInset
...@@ -122,12 +154,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -122,12 +154,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: buttonTopInset :name: buttonTopInset
*/ */
public var buttonTopInset: CGFloat = MaterialTheme.verticalInset public var buttonTopInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/** /**
:name: buttonBottomInset :name: buttonBottomInset
*/ */
public var buttonBottomInset: CGFloat = MaterialTheme.verticalInset public var buttonBottomInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/** /**
:name: buttonHorizontalInset :name: buttonHorizontalInset
...@@ -142,17 +182,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -142,17 +182,20 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: buttonLeftInset :name: buttonLeftInset
*/ */
public var buttonLeftInset: CGFloat = MaterialTheme.horizontalInset public var buttonLeftInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
prepareCard()
}
}
/** /**
:name: buttonRightInset :name: buttonRightInset
*/ */
public var buttonRightInset: CGFloat = MaterialTheme.horizontalInset public var buttonRightInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
/** prepareCard()
:name: titleLabelContainer }
*/ }
public private(set) var titleLabelContainer: UIView?
/** /**
:name: shadow :name: shadow
...@@ -160,10 +203,34 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -160,10 +203,34 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
public var shadow: Bool = true { public var shadow: Bool = true {
didSet { didSet {
false == shadow ? removeShadow() : prepareShadow() false == shadow ? removeShadow() : prepareShadow()
prepareCard()
}
}
/**
:name: maximumImageViewHeight
*/
public var maximumImageViewHeight: CGFloat = 200 {
didSet {
prepareCard()
}
}
/**
:name: maximumTitleLabelHeight
*/
public var maximumTitleLabelHeight: CGFloat = 0 {
didSet {
prepareCard()
} }
} }
/** /**
:name: titleLabelContainer
*/
public private(set) var titleLabelContainer: UIView?
/**
:name: titleLabel :name: titleLabel
*/ */
public var titleLabel: UILabel? { public var titleLabel: UILabel? {
...@@ -173,29 +240,33 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -173,29 +240,33 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
if nil == titleLabelContainer { if nil == titleLabelContainer {
titleLabelContainer = UIView() titleLabelContainer = UIView()
titleLabelContainer!.setTranslatesAutoresizingMaskIntoConstraints(false) titleLabelContainer!.setTranslatesAutoresizingMaskIntoConstraints(false)
titleLabelContainer!.backgroundColor = MaterialTheme.clear.color titleLabelContainer!.backgroundColor = MaterialTheme.white.color
addSubview(titleLabelContainer!) addSubview(titleLabelContainer!)
} }
// text // text
titleLabelContainer!.addSubview(t) titleLabelContainer!.addSubview(t)
t.setTranslatesAutoresizingMaskIntoConstraints(false) t.setTranslatesAutoresizingMaskIntoConstraints(false)
t.textColor = MaterialTheme.white.color
t.backgroundColor = MaterialTheme.clear.color t.backgroundColor = MaterialTheme.clear.color
t.font = Roboto.medium t.font = Roboto.medium
t.numberOfLines = 1 t.numberOfLines = 0
t.lineBreakMode = .ByTruncatingTail t.lineBreakMode = .ByTruncatingTail
prepareCard() t.textColor = MaterialTheme.black.color
} else { } else {
titleLabelContainer?.removeFromSuperview() titleLabelContainer?.removeFromSuperview()
} }
prepareCard()
} }
} }
/** /**
:name: maximumDetailLabelHeight :name: maximumDetailLabelHeight
*/ */
public var maximumDetailLabelHeight: CGFloat = 144 public var maximumDetailLabelHeight: CGFloat = 144 {
didSet {
prepareCard()
}
}
/** /**
:name: detailLabelContainer :name: detailLabelContainer
...@@ -212,22 +283,22 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -212,22 +283,22 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
if nil == detailLabelContainer { if nil == detailLabelContainer {
detailLabelContainer = UIView() detailLabelContainer = UIView()
detailLabelContainer!.setTranslatesAutoresizingMaskIntoConstraints(false) detailLabelContainer!.setTranslatesAutoresizingMaskIntoConstraints(false)
detailLabelContainer!.backgroundColor = MaterialTheme.clear.color detailLabelContainer!.backgroundColor = MaterialTheme.white.color
addSubview(detailLabelContainer!) addSubview(detailLabelContainer!)
} }
// text // text
detailLabelContainer!.addSubview(l) detailLabelContainer!.addSubview(l)
l.setTranslatesAutoresizingMaskIntoConstraints(false) l.setTranslatesAutoresizingMaskIntoConstraints(false)
l.textColor = MaterialTheme.white.color l.textColor = MaterialTheme.black.color
l.backgroundColor = MaterialTheme.clear.color l.backgroundColor = MaterialTheme.clear.color
l.font = Roboto.light l.font = Roboto.light
l.numberOfLines = 0 l.numberOfLines = 0
l.lineBreakMode = .ByTruncatingTail l.lineBreakMode = .ByTruncatingTail
prepareCard()
} else { } else {
detailLabelContainer?.removeFromSuperview() detailLabelContainer?.removeFromSuperview()
} }
prepareCard()
} }
} }
...@@ -238,12 +309,12 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -238,12 +309,12 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
didSet { didSet {
if let d = divider { if let d = divider {
d.setTranslatesAutoresizingMaskIntoConstraints(false) d.setTranslatesAutoresizingMaskIntoConstraints(false)
d.backgroundColor = MaterialTheme.blueGrey.color d.backgroundColor = MaterialTheme.blueGrey.lighten5
addSubview(d) addSubview(d)
prepareCard()
} else { } else {
divider?.removeFromSuperview() divider?.removeFromSuperview()
} }
prepareCard()
} }
} }
...@@ -261,13 +332,13 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -261,13 +332,13 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
if nil == buttonsContainer { if nil == buttonsContainer {
buttonsContainer = UIView() buttonsContainer = UIView()
buttonsContainer!.setTranslatesAutoresizingMaskIntoConstraints(false) buttonsContainer!.setTranslatesAutoresizingMaskIntoConstraints(false)
buttonsContainer!.backgroundColor = MaterialTheme.clear.color buttonsContainer!.backgroundColor = MaterialTheme.white.color
addSubview(buttonsContainer!) addSubview(buttonsContainer!)
} }
prepareCard()
} else { } else {
buttonsContainer?.removeFromSuperview() buttonsContainer?.removeFromSuperview()
} }
prepareCard()
} }
} }
...@@ -280,13 +351,13 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -280,13 +351,13 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
if nil == buttonsContainer { if nil == buttonsContainer {
buttonsContainer = UIView() buttonsContainer = UIView()
buttonsContainer!.setTranslatesAutoresizingMaskIntoConstraints(false) buttonsContainer!.setTranslatesAutoresizingMaskIntoConstraints(false)
buttonsContainer!.backgroundColor = MaterialTheme.clear.color buttonsContainer!.backgroundColor = MaterialTheme.white.color
addSubview(buttonsContainer!) addSubview(buttonsContainer!)
} }
prepareCard()
} else { } else {
buttonsContainer?.removeFromSuperview() buttonsContainer?.removeFromSuperview()
} }
prepareCard()
} }
} }
...@@ -304,14 +375,14 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -304,14 +375,14 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
self.init(frame: CGRectZero) self.init(frame: CGRectZero)
prepareProperties(titleLabel, detailLabel: detailLabel, divider: divider, leftButtons: leftButtons, rightButtons: rightButtons) prepareProperties(titleLabel, detailLabel: detailLabel, divider: divider, leftButtons: leftButtons, rightButtons: rightButtons)
} }
/** /**
:name: init :name: init
*/ */
public required init(frame: CGRect) { public required init(frame: CGRect) {
super.init(frame: CGRectZero) super.init(frame: CGRectZero)
} }
// //
// :name: prepareProperties // :name: prepareProperties
// //
...@@ -329,7 +400,7 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -329,7 +400,7 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
internal override func prepareView() { internal override func prepareView() {
super.prepareView() super.prepareView()
prepareShadow() prepareShadow()
backgroundColor = MaterialTheme.blueGrey.darken1 backgroundColor = MaterialTheme.clear.color
} }
// //
...@@ -337,8 +408,7 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -337,8 +408,7 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
// //
internal override func prepareCard() { internal override func prepareCard() {
super.prepareCard() super.prepareCard()
// clear all constraints
// deactivate and clear all constraints
NSLayoutConstraint.deactivateConstraints(layoutConstraints) NSLayoutConstraint.deactivateConstraints(layoutConstraints)
layoutConstraints.removeAll(keepCapacity: false) layoutConstraints.removeAll(keepCapacity: false)
...@@ -354,10 +424,14 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable { ...@@ -354,10 +424,14 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
layoutConstraints += Layout.constraint("H:|[titleLabelContainer]|", options: nil, metrics: nil, views: ["titleLabelContainer": titleLabelContainer!]) layoutConstraints += Layout.constraint("H:|[titleLabelContainer]|", options: nil, metrics: nil, views: ["titleLabelContainer": titleLabelContainer!])
verticalFormat += "[titleLabelContainer]" verticalFormat += "[titleLabelContainer]"
views["titleLabelContainer"] = titleLabelContainer! views["titleLabelContainer"] = titleLabelContainer!
// common text // common text
Layout.height(titleLabelContainer!, child: titleLabel!, height: 1.5 * titleLabel!.font.pointSize) if 0 == maximumTitleLabelHeight {
Layout.expandToParentWithPad(titleLabelContainer!, child: titleLabel!, top: titleLabelTopInset, left: titleLabelLeftInset, bottom: titleLabelBottomInset, right: titleLabelRightInset) Layout.expandToParentWithPad(titleLabelContainer!, child: titleLabel!, top: titleLabelTopInset, left: titleLabelLeftInset, bottom: titleLabelBottomInset, right: titleLabelRightInset)
} else {
Layout.expandToParentHorizontallyWithPad(titleLabelContainer!, child: titleLabel!, left: titleLabelLeftInset, right: titleLabelRightInset)
titleLabelContainer!.addConstraints(Layout.constraint("V:|-(titleLabelTopInset)-[titleLabel(<=maximumTitleLabelHeight)]-(titleLabelBottomInset)-|", options: nil, metrics: ["titleLabelTopInset": titleLabelTopInset, "titleLabelBottomInset": titleLabelBottomInset, "maximumTitleLabelHeight": maximumTitleLabelHeight], views: ["titleLabel": titleLabel!]))
}
} }
// detail // detail
......
...@@ -42,12 +42,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -42,12 +42,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: imageViewTopInset :name: imageViewTopInset
*/ */
public var imageViewTopInset: CGFloat = 0 public var imageViewTopInset: CGFloat = 0 {
didSet {
prepareCard()
}
}
/** /**
:name: imageViewBottomInset :name: imageViewBottomInset
*/ */
public var imageViewBottomInset: CGFloat = 0 public var imageViewBottomInset: CGFloat = 0 {
didSet {
prepareCard()
}
}
/** /**
:name: imageViewHorizontalInset :name: imageViewHorizontalInset
...@@ -62,26 +70,48 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -62,26 +70,48 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: imageViewLeftInset :name: imageViewLeftInset
*/ */
public var imageViewLeftInset: CGFloat = 0 public var imageViewLeftInset: CGFloat = 0 {
didSet {
prepareCard()
}
}
/** /**
:name: imageViewRightInset :name: imageViewRightInset
*/ */
public var imageViewRightInset: CGFloat = 0 public var imageViewRightInset: CGFloat = 0 {
didSet {
prepareCard()
}
}
/** /**
:name: titleLabelVerticalInset :name: titleLabelVerticalInset
*/ */
public var titleLabelVerticalInset: CGFloat = MaterialTheme.verticalInset { public var titleLabelVerticalInset: CGFloat = MaterialTheme.verticalInset {
didSet { didSet {
titleLabelTopInset = titleLabelVerticalInset
titleLabelBottomInset = titleLabelVerticalInset titleLabelBottomInset = titleLabelVerticalInset
} }
} }
/** /**
:name: titleLabelTopInset
*/
public var titleLabelTopInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/**
:name: titleLabelBottomInset :name: titleLabelBottomInset
*/ */
public var titleLabelBottomInset: CGFloat = MaterialTheme.verticalInset public var titleLabelBottomInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/** /**
:name: titleLabelHorizontalInset :name: titleLabelHorizontalInset
...@@ -96,12 +126,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -96,12 +126,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: titleLabelLeftInset :name: titleLabelLeftInset
*/ */
public var titleLabelLeftInset: CGFloat = MaterialTheme.horizontalInset public var titleLabelLeftInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
prepareCard()
}
}
/** /**
:name: titleLabelRightInset :name: titleLabelRightInset
*/ */
public var titleLabelRightInset: CGFloat = MaterialTheme.horizontalInset public var titleLabelRightInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
prepareCard()
}
}
/** /**
:name: detailLabelVerticalInset :name: detailLabelVerticalInset
...@@ -116,12 +154,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -116,12 +154,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: detailLabelTopInset :name: detailLabelTopInset
*/ */
public var detailLabelTopInset: CGFloat = MaterialTheme.verticalInset public var detailLabelTopInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/** /**
:name: detailLabelBottomInset :name: detailLabelBottomInset
*/ */
public var detailLabelBottomInset: CGFloat = MaterialTheme.verticalInset public var detailLabelBottomInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/** /**
:name: detailLabelHorizontalInset :name: detailLabelHorizontalInset
...@@ -136,12 +182,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -136,12 +182,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: detailLabelLeftInset :name: detailLabelLeftInset
*/ */
public var detailLabelLeftInset: CGFloat = MaterialTheme.horizontalInset public var detailLabelLeftInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
prepareCard()
}
}
/** /**
:name: detailLabelRightInset :name: detailLabelRightInset
*/ */
public var detailLabelRightInset: CGFloat = MaterialTheme.horizontalInset public var detailLabelRightInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
prepareCard()
}
}
/** /**
:name: buttonVerticalInset :name: buttonVerticalInset
...@@ -156,12 +210,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -156,12 +210,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: buttonTopInset :name: buttonTopInset
*/ */
public var buttonTopInset: CGFloat = MaterialTheme.verticalInset public var buttonTopInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/** /**
:name: buttonBottomInset :name: buttonBottomInset
*/ */
public var buttonBottomInset: CGFloat = MaterialTheme.verticalInset public var buttonBottomInset: CGFloat = MaterialTheme.verticalInset {
didSet {
prepareCard()
}
}
/** /**
:name: buttonHorizontalInset :name: buttonHorizontalInset
...@@ -176,12 +238,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -176,12 +238,20 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
/** /**
:name: buttonLeftInset :name: buttonLeftInset
*/ */
public var buttonLeftInset: CGFloat = MaterialTheme.horizontalInset public var buttonLeftInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
prepareCard()
}
}
/** /**
:name: buttonRightInset :name: buttonRightInset
*/ */
public var buttonRightInset: CGFloat = MaterialTheme.horizontalInset public var buttonRightInset: CGFloat = MaterialTheme.horizontalInset {
didSet {
prepareCard()
}
}
/** /**
:name: shadow :name: shadow
...@@ -189,13 +259,18 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -189,13 +259,18 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
public var shadow: Bool = true { public var shadow: Bool = true {
didSet { didSet {
false == shadow ? removeShadow() : prepareShadow() false == shadow ? removeShadow() : prepareShadow()
prepareCard()
} }
} }
/** /**
:name: maximumImageViewHeight :name: maximumImageViewHeight
*/ */
public var maximumImageViewHeight: CGFloat = 200 public var maximumImageViewHeight: CGFloat = 200 {
didSet {
prepareCard()
}
}
/** /**
:name: imageViewContainer :name: imageViewContainer
...@@ -228,10 +303,19 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -228,10 +303,19 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
titleLabelContainer!.removeFromSuperview() titleLabelContainer!.removeFromSuperview()
imageViewContainer!.addSubview(titleLabelContainer!) imageViewContainer!.addSubview(titleLabelContainer!)
} }
prepareCard()
} else { } else {
imageViewContainer?.removeFromSuperview() imageViewContainer?.removeFromSuperview()
} }
prepareCard()
}
}
/**
:name: maximumTitleLabelHeight
*/
public var maximumTitleLabelHeight: CGFloat = 0 {
didSet {
prepareCard()
} }
} }
...@@ -258,7 +342,7 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -258,7 +342,7 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
t.setTranslatesAutoresizingMaskIntoConstraints(false) t.setTranslatesAutoresizingMaskIntoConstraints(false)
t.backgroundColor = MaterialTheme.clear.color t.backgroundColor = MaterialTheme.clear.color
t.font = Roboto.medium t.font = Roboto.medium
t.numberOfLines = 1 t.numberOfLines = 0
t.lineBreakMode = .ByTruncatingTail t.lineBreakMode = .ByTruncatingTail
if nil == imageView { if nil == imageView {
titleLabelContainer!.backgroundColor = MaterialTheme.white.color titleLabelContainer!.backgroundColor = MaterialTheme.white.color
...@@ -269,17 +353,21 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -269,17 +353,21 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
titleLabelContainer!.removeFromSuperview() titleLabelContainer!.removeFromSuperview()
imageViewContainer!.addSubview(titleLabelContainer!) imageViewContainer!.addSubview(titleLabelContainer!)
} }
prepareCard()
} else { } else {
titleLabelContainer?.removeFromSuperview() titleLabelContainer?.removeFromSuperview()
} }
prepareCard()
} }
} }
/** /**
:name: maximumDetailLabelHeight :name: maximumDetailLabelHeight
*/ */
public var maximumDetailLabelHeight: CGFloat = 144 public var maximumDetailLabelHeight: CGFloat = 144 {
didSet {
prepareCard()
}
}
/** /**
:name: detailLabelContainer :name: detailLabelContainer
...@@ -308,10 +396,10 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -308,10 +396,10 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
l.font = Roboto.light l.font = Roboto.light
l.numberOfLines = 0 l.numberOfLines = 0
l.lineBreakMode = .ByTruncatingTail l.lineBreakMode = .ByTruncatingTail
prepareCard()
} else { } else {
detailLabelContainer?.removeFromSuperview() detailLabelContainer?.removeFromSuperview()
} }
prepareCard()
} }
} }
...@@ -324,10 +412,10 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -324,10 +412,10 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
d.setTranslatesAutoresizingMaskIntoConstraints(false) d.setTranslatesAutoresizingMaskIntoConstraints(false)
d.backgroundColor = MaterialTheme.blueGrey.lighten5 d.backgroundColor = MaterialTheme.blueGrey.lighten5
addSubview(d) addSubview(d)
prepareCard()
} else { } else {
divider?.removeFromSuperview() divider?.removeFromSuperview()
} }
prepareCard()
} }
} }
...@@ -348,10 +436,10 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -348,10 +436,10 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
buttonsContainer!.backgroundColor = MaterialTheme.white.color buttonsContainer!.backgroundColor = MaterialTheme.white.color
addSubview(buttonsContainer!) addSubview(buttonsContainer!)
} }
prepareCard()
} else { } else {
buttonsContainer?.removeFromSuperview() buttonsContainer?.removeFromSuperview()
} }
prepareCard()
} }
} }
...@@ -367,10 +455,10 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -367,10 +455,10 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
buttonsContainer!.backgroundColor = MaterialTheme.white.color buttonsContainer!.backgroundColor = MaterialTheme.white.color
addSubview(buttonsContainer!) addSubview(buttonsContainer!)
} }
prepareCard()
} else { } else {
buttonsContainer?.removeFromSuperview() buttonsContainer?.removeFromSuperview()
} }
prepareCard()
} }
} }
...@@ -422,8 +510,7 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -422,8 +510,7 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
// //
internal override func prepareCard() { internal override func prepareCard() {
super.prepareCard() super.prepareCard()
// clear all constraints
// deactivate and clear all constraints
NSLayoutConstraint.deactivateConstraints(layoutConstraints) NSLayoutConstraint.deactivateConstraints(layoutConstraints)
layoutConstraints.removeAll(keepCapacity: false) layoutConstraints.removeAll(keepCapacity: false)
...@@ -462,8 +549,12 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable { ...@@ -462,8 +549,12 @@ public class ImageCardView : MaterialCardView, Comparable, Equatable {
} }
// common text // common text
Layout.height(titleLabelContainer!, child: titleLabel!, height: 1.5 * titleLabel!.font.pointSize) if 0 == maximumTitleLabelHeight {
Layout.expandToParentWithPad(titleLabelContainer!, child: titleLabel!, left: titleLabelLeftInset, bottom: titleLabelBottomInset, right: titleLabelRightInset) Layout.expandToParentWithPad(titleLabelContainer!, child: titleLabel!, top: titleLabelTopInset, left: titleLabelLeftInset, bottom: titleLabelBottomInset, right: titleLabelRightInset)
} else {
Layout.expandToParentHorizontallyWithPad(titleLabelContainer!, child: titleLabel!, left: titleLabelLeftInset, right: titleLabelRightInset)
titleLabelContainer!.addConstraints(Layout.constraint("V:|-(titleLabelTopInset)-[titleLabel(<=maximumTitleLabelHeight)]-(titleLabelBottomInset)-|", options: nil, metrics: ["titleLabelTopInset": titleLabelTopInset, "titleLabelBottomInset": titleLabelBottomInset, "maximumTitleLabelHeight": maximumTitleLabelHeight], views: ["titleLabel": titleLabel!]))
}
} }
// detail // detail
......
...@@ -20,6 +20,17 @@ import UIKit ...@@ -20,6 +20,17 @@ import UIKit
public struct MaterialTheme {} public struct MaterialTheme {}
// spacing
extension MaterialTheme {
public static var verticalInset: CGFloat = 16
public static var horizontalInset: CGFloat = 16
}
// fonts
extension MaterialTheme {
public static var textFontSize: CGFloat = 16
}
// colors // colors
extension MaterialTheme { extension MaterialTheme {
// clear // clear
...@@ -369,14 +380,3 @@ extension MaterialTheme { ...@@ -369,14 +380,3 @@ extension MaterialTheme {
public static let darken4: UIColor = UIColor(red: 38/255, green: 50/255, blue: 56/255, alpha: 1) public static let darken4: UIColor = UIColor(red: 38/255, green: 50/255, blue: 56/255, alpha: 1)
} }
} }
// spacing
extension MaterialTheme {
public static var verticalInset: CGFloat = 8
public static var horizontalInset: CGFloat = 2 * verticalInset
}
// fonts
extension MaterialTheme {
public static var textFontSize: CGFloat = 16
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment