Commit e697f176 by Daniel Dahan

development: handle nil values set to BasicCard

parent a86fc878
...@@ -58,21 +58,26 @@ public class BasicCard : MaterialCard { ...@@ -58,21 +58,26 @@ public class BasicCard : MaterialCard {
*/ */
public var titleLabel: UILabel? { public var titleLabel: UILabel? {
didSet { didSet {
// container if let t = titleLabel {
if nil == titleLabelContainer { // container
titleLabelContainer = UIView() if nil == titleLabelContainer {
titleLabelContainer!.setTranslatesAutoresizingMaskIntoConstraints(false) titleLabelContainer = UIView()
titleLabelContainer!.backgroundColor = MaterialTheme.clear.color titleLabelContainer!.setTranslatesAutoresizingMaskIntoConstraints(false)
addSubview(titleLabelContainer!) titleLabelContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(titleLabelContainer!)
}
// text
titleLabelContainer!.addSubview(t)
t.setTranslatesAutoresizingMaskIntoConstraints(false)
t.textColor = MaterialTheme.white.color
t.backgroundColor = MaterialTheme.clear.color
t.font = Roboto.mediumWithSize(18)
t.numberOfLines = 1
} else {
titleLabel?.removeFromSuperview()
titleLabelContainer?.removeFromSuperview()
} }
// text
titleLabelContainer!.addSubview(titleLabel!)
titleLabel!.setTranslatesAutoresizingMaskIntoConstraints(false)
titleLabel!.textColor = MaterialTheme.white.color
titleLabel!.backgroundColor = MaterialTheme.clear.color
titleLabel!.font = Roboto.mediumWithSize(18)
titleLabel!.numberOfLines = 1
} }
} }
...@@ -86,23 +91,28 @@ public class BasicCard : MaterialCard { ...@@ -86,23 +91,28 @@ public class BasicCard : MaterialCard {
*/ */
public var detailLabel: UILabel? { public var detailLabel: UILabel? {
didSet { didSet {
// container if let l = detailLabel {
if nil == detailLabelContainer { // container
detailLabelContainer = UIView() if nil == detailLabelContainer {
detailLabelContainer!.setTranslatesAutoresizingMaskIntoConstraints(false) detailLabelContainer = UIView()
detailLabelContainer!.backgroundColor = MaterialTheme.clear.color detailLabelContainer!.setTranslatesAutoresizingMaskIntoConstraints(false)
addSubview(detailLabelContainer!) detailLabelContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(detailLabelContainer!)
}
// text
detailLabelContainer!.addSubview(l)
l.setTranslatesAutoresizingMaskIntoConstraints(false)
l.textColor = MaterialTheme.white.color
l.backgroundColor = MaterialTheme.clear.color
l.font = Roboto.lightWithSize(12)
l.numberOfLines = 0
l.lineBreakMode = .ByWordWrapping
prepareCard()
} else {
detailLabel?.removeFromSuperview()
detailLabelContainer?.removeFromSuperview()
} }
// text
detailLabelContainer!.addSubview(detailLabel!)
detailLabel!.setTranslatesAutoresizingMaskIntoConstraints(false)
detailLabel!.textColor = MaterialTheme.white.color
detailLabel!.backgroundColor = MaterialTheme.clear.color
detailLabel!.font = Roboto.lightWithSize(12)
detailLabel!.numberOfLines = 0
detailLabel!.lineBreakMode = .ByWordWrapping
prepareCard()
} }
} }
...@@ -111,10 +121,14 @@ public class BasicCard : MaterialCard { ...@@ -111,10 +121,14 @@ public class BasicCard : MaterialCard {
*/ */
public var divider: UIView? { public var divider: UIView? {
didSet { didSet {
divider!.setTranslatesAutoresizingMaskIntoConstraints(false) if let d = divider {
divider!.backgroundColor = MaterialTheme.blueGrey.color d.setTranslatesAutoresizingMaskIntoConstraints(false)
addSubview(divider!) d.backgroundColor = MaterialTheme.blueGrey.color
prepareCard() addSubview(d)
prepareCard()
} else {
divider?.removeFromSuperview()
}
} }
} }
...@@ -128,13 +142,17 @@ public class BasicCard : MaterialCard { ...@@ -128,13 +142,17 @@ public class BasicCard : MaterialCard {
*/ */
public var leftButtons: Array<MaterialButton>? { public var leftButtons: Array<MaterialButton>? {
didSet { didSet {
if nil == buttonsContainer { if let b = leftButtons {
buttonsContainer = UIView() if nil == buttonsContainer {
buttonsContainer!.setTranslatesAutoresizingMaskIntoConstraints(false) buttonsContainer = UIView()
buttonsContainer!.backgroundColor = MaterialTheme.clear.color buttonsContainer!.setTranslatesAutoresizingMaskIntoConstraints(false)
addSubview(buttonsContainer!) buttonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(buttonsContainer!)
}
prepareCard()
} else {
buttonsContainer?.removeFromSuperview()
} }
prepareCard()
} }
} }
...@@ -143,13 +161,17 @@ public class BasicCard : MaterialCard { ...@@ -143,13 +161,17 @@ public class BasicCard : MaterialCard {
*/ */
public var rightButtons: Array<MaterialButton>? { public var rightButtons: Array<MaterialButton>? {
didSet { didSet {
if nil == buttonsContainer { if let b = rightButtons {
buttonsContainer = UIView() if nil == buttonsContainer {
buttonsContainer!.setTranslatesAutoresizingMaskIntoConstraints(false) buttonsContainer = UIView()
buttonsContainer!.backgroundColor = MaterialTheme.clear.color buttonsContainer!.setTranslatesAutoresizingMaskIntoConstraints(false)
addSubview(buttonsContainer!) buttonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(buttonsContainer!)
}
prepareCard()
} else {
buttonsContainer?.removeFromSuperview()
} }
prepareCard()
} }
} }
......
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