Commit 03ada092 by Daniel Dahan

updated BasicCard

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