Commit 03ada092 by Daniel Dahan

updated BasicCard

parent 48b9d4e9
...@@ -29,74 +29,100 @@ public class BasicCard : MaterialCard { ...@@ -29,74 +29,100 @@ public class BasicCard : MaterialCard {
// //
internal lazy var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() internal lazy var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
// /**
// :name: detailTextContainer :name: verticalSpace
// */
internal var detailTextContainer: UIView? public var verticalSpace: CGFloat = 8
// /**
// :name: buttonsContainer :name: maximumDetailHeight
// */
internal var buttonsContainer: UIView? public var maximumDetailHeight: CGFloat = 144
/**
:name: titleLabelContainer
*/
public private(set) var titleLabelContainer: UIView?
/** /**
:name: titleLabel :name: titleLabel
*/ */
public var titleLabel: UILabel? { public var titleLabel: UILabel? {
didSet { didSet {
// container
if nil == titleLabelContainer {
titleLabelContainer = UIView()
titleLabelContainer!.setTranslatesAutoresizingMaskIntoConstraints(false)
titleLabelContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(titleLabelContainer!)
}
// text
titleLabelContainer!.addSubview(titleLabel!)
titleLabel!.setTranslatesAutoresizingMaskIntoConstraints(false) titleLabel!.setTranslatesAutoresizingMaskIntoConstraints(false)
titleLabel!.textColor = MaterialTheme.white.color titleLabel!.textColor = MaterialTheme.white.color
titleLabel!.font = Roboto.regularWithSize(24) titleLabel!.backgroundColor = MaterialTheme.clear.color
addSubview(titleLabel!) titleLabel!.font = Roboto.regularWithSize(18)
prepareCard() titleLabel!.numberOfLines = 1
} }
} }
/** /**
:name: detailTextLabel :name: detailLabelContainer
*/ */
public var detailTextLabel: UILabel? { public private(set) var detailLabelContainer: UIView?
/**
:name: detailLabel
*/
public var detailLabel: UILabel? {
didSet { didSet {
// container // container
if nil == detailTextContainer { if nil == detailLabelContainer {
detailTextContainer = UIView() detailLabelContainer = UIView()
detailTextContainer!.setTranslatesAutoresizingMaskIntoConstraints(false) detailLabelContainer!.setTranslatesAutoresizingMaskIntoConstraints(false)
detailTextContainer!.backgroundColor = MaterialTheme.white.color detailLabelContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(detailTextContainer!) addSubview(detailLabelContainer!)
} }
// text // text
detailTextContainer!.addSubview(detailTextLabel!) detailLabelContainer!.addSubview(detailLabel!)
detailTextLabel!.setTranslatesAutoresizingMaskIntoConstraints(false) detailLabel!.setTranslatesAutoresizingMaskIntoConstraints(false)
detailTextLabel!.textColor = MaterialTheme.black.color detailLabel!.textColor = MaterialTheme.white.color
detailTextLabel!.font = Roboto.lightWithSize(14) detailLabel!.backgroundColor = MaterialTheme.clear.color
detailTextLabel!.numberOfLines = 0 detailLabel!.font = Roboto.lightWithSize(14)
detailTextLabel!.lineBreakMode = .ByWordWrapping detailLabel!.numberOfLines = 0
detailLabel!.lineBreakMode = .ByWordWrapping
prepareCard() prepareCard()
} }
} }
/** /**
:name: divider :name: divider
*/ */
public var divider: UIView? { public var divider: UIView? {
didSet { didSet {
divider!.setTranslatesAutoresizingMaskIntoConstraints(false) divider!.setTranslatesAutoresizingMaskIntoConstraints(false)
divider!.backgroundColor = MaterialTheme.blueGrey.lighten4 divider!.backgroundColor = MaterialTheme.blueGrey.color
addSubview(divider!) addSubview(divider!)
prepareCard() prepareCard()
} }
} }
/** /**
:name: buttons :name: buttonsContainer
*/
public private(set) var buttonsContainer: UIView?
/**
:name: buttons
*/ */
public var buttons: Array<MaterialButton>? { public var buttons: Array<MaterialButton>? {
didSet { didSet {
if nil == buttonsContainer { if nil == buttonsContainer {
buttonsContainer = UIView() buttonsContainer = UIView()
buttonsContainer!.setTranslatesAutoresizingMaskIntoConstraints(false) buttonsContainer!.setTranslatesAutoresizingMaskIntoConstraints(false)
buttonsContainer!.backgroundColor = MaterialTheme.white.color buttonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(buttonsContainer!) addSubview(buttonsContainer!)
} }
prepareCard() prepareCard()
...@@ -109,7 +135,7 @@ public class BasicCard : MaterialCard { ...@@ -109,7 +135,7 @@ public class BasicCard : MaterialCard {
internal override func prepareView() { internal override func prepareView() {
super.prepareView() super.prepareView()
prepareShadow() prepareShadow()
backgroundColor = MaterialTheme.clear.color backgroundColor = MaterialTheme.blueGrey.darken1
} }
// //
...@@ -117,6 +143,7 @@ public class BasicCard : MaterialCard { ...@@ -117,6 +143,7 @@ public class BasicCard : MaterialCard {
// //
internal override func prepareCard() { internal override func prepareCard() {
super.prepareCard() super.prepareCard()
// deactivate and clear all constraints // deactivate and clear all constraints
NSLayoutConstraint.deactivateConstraints(layoutConstraints) NSLayoutConstraint.deactivateConstraints(layoutConstraints)
layoutConstraints.removeAll(keepCapacity: false) layoutConstraints.removeAll(keepCapacity: false)
...@@ -125,25 +152,30 @@ public class BasicCard : MaterialCard { ...@@ -125,25 +152,30 @@ public class BasicCard : MaterialCard {
var verticalFormat: String = "V:|" var verticalFormat: String = "V:|"
// title // title
if nil != titleLabel { if nil != titleLabelContainer && nil != titleLabel {
layoutConstraints += Layout.constraint("H:|-(16)-[titleLabel]-(16)-|", options: nil, metrics: nil, views: ["titleLabel": titleLabel!]) // container
verticalFormat += "-(16)-[titleLabel(24)]" layoutConstraints += Layout.constraint("H:|[titleLabelContainer]|", options: nil, metrics: nil, views: ["titleLabelContainer": titleLabelContainer!])
views["titleLabel"] = titleLabel! verticalFormat += "[titleLabelContainer]"
views["titleLabelContainer"] = titleLabelContainer!
// text
titleLabelContainer!.addConstraints(Layout.constraint("H:|-(verticalSpace)-[titleLabel]-(verticalSpace)-|", options: nil, metrics: ["verticalSpace": verticalSpace], views: ["titleLabel": titleLabel!]))
titleLabelContainer!.addConstraints(Layout.constraint("V:|-(verticalSpace)-[titleLabel]-(verticalSpace)-|", options: nil, metrics: ["verticalSpace": verticalSpace], views: ["titleLabel": titleLabel!]))
} }
// details // detail
if nil != detailTextContainer && nil != detailTextLabel { if nil != detailLabelContainer && nil != detailLabel {
// container // container
layoutConstraints += Layout.constraint("H:|[detailTextContainer]|", options: nil, metrics: nil, views: ["detailTextContainer": detailTextContainer!]) layoutConstraints += Layout.constraint("H:|[detailLabelContainer]|", options: nil, metrics: nil, views: ["detailLabelContainer": detailLabelContainer!])
verticalFormat += "[detailTextContainer]" verticalFormat += "[detailLabelContainer]"
views["detailTextContainer"] = detailTextContainer! views["detailLabelContainer"] = detailLabelContainer!
// text // text
detailTextContainer!.addConstraints(Layout.constraint("H:|-(16)-[detailTextLabel]-(16)-|", options: nil, metrics: nil, views: ["detailTextLabel": detailTextLabel!])) detailLabelContainer!.addConstraints(Layout.constraint("H:|-(verticalSpace)-[detailLabel]-(verticalSpace)-|", options: nil, metrics: ["verticalSpace": verticalSpace], views: ["detailLabel": detailLabel!]))
detailTextContainer!.addConstraints(Layout.constraint("V:|-(16)-[detailTextLabel(<=128)]|", options: nil, metrics: nil, views: ["detailTextLabel": detailTextLabel!])) detailLabelContainer!.addConstraints(Layout.constraint("V:|-(verticalSpace)-[detailLabel(<=maximumDetailHeight)]-(verticalSpace)-|", options: nil, metrics: ["verticalSpace": verticalSpace, "maximumDetailHeight": maximumDetailHeight], views: ["detailLabel": detailLabel!]))
} }
if nil != buttons && nil != buttonsContainer { if nil != buttonsContainer && nil != buttons {
// divider // divider
if nil != divider { if nil != divider {
layoutConstraints += Layout.constraint("H:|[divider]|", options: nil, metrics: nil, views: ["divider": divider!]) layoutConstraints += Layout.constraint("H:|[divider]|", options: nil, metrics: nil, views: ["divider": divider!])
...@@ -163,11 +195,10 @@ public class BasicCard : MaterialCard { ...@@ -163,11 +195,10 @@ public class BasicCard : MaterialCard {
let button: MaterialButton = buttons![i] let button: MaterialButton = buttons![i]
buttonsContainer!.addSubview(button) buttonsContainer!.addSubview(button)
buttonViews["button\(i)"] = button buttonViews["button\(i)"] = button
horizontalFormat += "-(8)-[button\(i)]" horizontalFormat += "-(verticalSpace)-[button\(i)]"
Layout.expandToParentVerticallyWithPad(buttonsContainer!, child: button, top: 8, bottom: 8) Layout.expandToParentVerticallyWithPad(buttonsContainer!, child: button, top: verticalSpace, bottom: verticalSpace)
buttonsContainer!.addConstraints(Layout.constraint(horizontalFormat, options: nil, metrics: nil, views: buttonViews))
} }
layoutConstraints += Layout.constraint(horizontalFormat, options: nil, metrics: nil, views: buttonViews) buttonsContainer!.addConstraints(Layout.constraint(horizontalFormat, options: nil, metrics: ["verticalSpace": verticalSpace], views: buttonViews))
} }
verticalFormat += "|" verticalFormat += "|"
......
...@@ -26,6 +26,7 @@ public class FabButton : MaterialButton { ...@@ -26,6 +26,7 @@ public class FabButton : MaterialButton {
super.prepareView() super.prepareView()
setTitleColor(MaterialTheme.white.color, forState: .Normal) setTitleColor(MaterialTheme.white.color, forState: .Normal)
backgroundColor = MaterialTheme.red.darken1 backgroundColor = MaterialTheme.red.darken1
contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)
} }
// //
......
...@@ -27,7 +27,7 @@ public class FlatButton : MaterialButton { ...@@ -27,7 +27,7 @@ public class FlatButton : MaterialButton {
setTitleColor(MaterialTheme.indigo.darken1, forState: .Normal) setTitleColor(MaterialTheme.indigo.darken1, forState: .Normal)
pulseColor = MaterialTheme.indigo.darken1 pulseColor = MaterialTheme.indigo.darken1
backgroundColor = MaterialTheme.clear.color backgroundColor = MaterialTheme.clear.color
contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20) contentEdgeInsets = UIEdgeInsetsMake(4, 4, 4, 4)
} }
// //
......
...@@ -117,6 +117,7 @@ public class MaterialCard : UIView { ...@@ -117,6 +117,7 @@ public class MaterialCard : UIView {
layer.shadowOffset = CGSizeMake(0.05, 0.05) layer.shadowOffset = CGSizeMake(0.05, 0.05)
layer.shadowOpacity = 0.1 layer.shadowOpacity = 0.1
layer.shadowRadius = 3 layer.shadowRadius = 3
layer.shadowPath = UIBezierPath(rect: bounds).CGPath
} }
// //
...@@ -124,7 +125,6 @@ public class MaterialCard : UIView { ...@@ -124,7 +125,6 @@ public class MaterialCard : UIView {
// //
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layer.shadowPath = UIBezierPath(rect: bounds).CGPath
} }
// //
......
...@@ -26,7 +26,7 @@ public class RaisedButton : MaterialButton { ...@@ -26,7 +26,7 @@ public class RaisedButton : MaterialButton {
super.prepareView() super.prepareView()
setTitleColor(MaterialTheme.white.color, forState: .Normal) setTitleColor(MaterialTheme.white.color, forState: .Normal)
backgroundColor = MaterialTheme.indigo.darken1 backgroundColor = MaterialTheme.indigo.darken1
contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20) contentEdgeInsets = UIEdgeInsetsMake(4, 4, 4, 4)
} }
// //
......
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