Commit a2d32af3 by Daniel Dahan

issue-7: added titleLabel and detailTextLabel to BasicCard

parent dd56c12a
...@@ -20,67 +20,118 @@ import UIKit ...@@ -20,67 +20,118 @@ import UIKit
import QuartzCore import QuartzCore
public class BasicCard : MaterialCard { public class BasicCard : MaterialCard {
public lazy var cancelButton: FlatButton = FlatButton() //
public lazy var otherButton: FlatButton = FlatButton() // :name: layoutConstraints
public lazy var buttonColor: UIColor = UIColor(red: 255.0/255.0, green: 156.0/255.0, blue: 38.0/255.0, alpha: 1.0) //
public lazy var titleLabel: UILabel = UILabel() internal lazy var layoutConstraints: Array<NSLayoutConstraint> = Array<NSLayoutConstraint>()
public lazy var detailTextLabel: UILabel = UILabel() //
public lazy var horizontalSeparator: UIView = UIView() // :name: views
//
internal lazy var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
/**
:name: buttons
*/
public var buttons: Array<MaterialButton>?
/**
:name: titleLabel
*/
public var titleLabel: UILabel? {
didSet {
titleLabel!.setTranslatesAutoresizingMaskIntoConstraints(false)
titleLabel!.font = Roboto.regularWithSize(22.0)
addSubview(titleLabel!)
prepareCard()
}
}
/**
:name: detailTextLabel
*/
public var detailTextLabel: UILabel? {
didSet {
detailTextLabel!.setTranslatesAutoresizingMaskIntoConstraints(false)
detailTextLabel!.font = Roboto.lightWithSize(16.0)
detailTextLabel!.numberOfLines = 0
detailTextLabel!.lineBreakMode = .ByWordWrapping
addSubview(detailTextLabel!)
prepareCard()
}
}
public var horizontalSeparator: UIView?
internal override func prepareCard() { internal override func prepareCard() {
super.prepareCard() super.prepareCard()
prepareShadow() prepareShadow()
prepareTitleLabel()
prepareDetailTextLabel() // deactivate and clear all constraints
prepareHorizontalSeparator() NSLayoutConstraint.deactivateConstraints(layoutConstraints)
prepareCancelButton() layoutConstraints.removeAll(keepCapacity: false)
prepareOtherButton()
addConstraints(Layout.constraint("H:|-(20)-[titleLabel]-(20)-|", options: nil, metrics: nil, views: ["titleLabel": titleLabel])) // detect all components and create constraints
addConstraints(Layout.constraint("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: ["detailTextLabel": detailTextLabel])) var verticalFormat: String = "V:|"
addConstraints(Layout.constraint("H:|[horizontalSeparator]|", options: nil, metrics: nil, views: ["horizontalSeparator": horizontalSeparator]))
addConstraints(Layout.constraint("H:|-(10)-[cancelButton(80)]-(10)-[otherButton(80)]", options: nil, metrics: nil, views: ["cancelButton": cancelButton, "otherButton": otherButton])) // title
addConstraints(Layout.constraint("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[horizontalSeparator(1)]-(10)-[cancelButton]-(10)-|", options: nil, metrics: nil, views: ["titleLabel": titleLabel, "detailTextLabel": detailTextLabel, "horizontalSeparator": horizontalSeparator, "cancelButton": cancelButton, "otherButton": otherButton])) if nil != titleLabel {
addConstraints(Layout.constraint("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[horizontalSeparator(1)]-(10)-[otherButton]-(10)-|", options: nil, metrics: nil, views: ["titleLabel": titleLabel, "detailTextLabel": detailTextLabel, "horizontalSeparator": horizontalSeparator, "otherButton": otherButton])) layoutConstraints += Layout.constraint("H:|-(20)-[titleLabel]-(20)-|", options: nil, metrics: nil, views: ["titleLabel": titleLabel!])
verticalFormat += "-(20)-[titleLabel(22)]"
views["titleLabel"] = titleLabel!
}
// details
if nil != detailTextLabel {
layoutConstraints += Layout.constraint("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: ["detailTextLabel": detailTextLabel!])
verticalFormat += "-(20)-[detailTextLabel]"
views["detailTextLabel"] = detailTextLabel!
}
// addConstraints(Layout.constraint("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: ["detailTextLabel": detailTextLabel]))
// addConstraints(Layout.constraint("H:|[horizontalSeparator]|", options: nil, metrics: nil, views: ["horizontalSeparator": horizontalSeparator]))
// addConstraints(Layout.constraint("H:|-(10)-[cancelButton(80)]-(10)-[otherButton(80)]", options: nil, metrics: nil, views: ["cancelButton": cancelButton, "otherButton": otherButton]))
// addConstraints(Layout.constraint("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[horizontalSeparator(1)]-(10)-[cancelButton]-(10)-|", options: nil, metrics: nil, views: ["titleLabel": titleLabel, "detailTextLabel": detailTextLabel, "horizontalSeparator": horizontalSeparator, "cancelButton": cancelButton, "otherButton": otherButton]))
// addConstraints(Layout.constraint("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[horizontalSeparator(1)]-(10)-[otherButton]-(10)-|", options: nil, metrics: nil, views: ["titleLabel": titleLabel, "detailTextLabel": detailTextLabel, "horizontalSeparator": horizontalSeparator, "otherButton": otherButton]))
if 0 < layoutConstraints.count {
verticalFormat += "-(20)-|"
layoutConstraints += Layout.constraint(verticalFormat, options: nil, metrics: nil, views: views)
NSLayoutConstraint.activateConstraints(layoutConstraints)
}
} }
private func prepareTitleLabel() { //
titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false) // private func prepareDetailTextLabel() {
titleLabel.font = Roboto.regularWithSize(22.0) // detailTextLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
titleLabel.textColor = UIColor.whiteColor() // detailTextLabel.font = Roboto.lightWithSize(16.0)
titleLabel.text = "Card Title" // detailTextLabel.textColor = UIColor.whiteColor()
addSubview(titleLabel) // detailTextLabel.text = "I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively."
} // detailTextLabel.numberOfLines = 0
// detailTextLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
private func prepareDetailTextLabel() { // addSubview(detailTextLabel)
detailTextLabel.setTranslatesAutoresizingMaskIntoConstraints(false) // }
detailTextLabel.font = Roboto.lightWithSize(16.0) //
detailTextLabel.textColor = UIColor.whiteColor() // private func prepareHorizontalSeparator() {
detailTextLabel.text = "I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively." // horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false)
detailTextLabel.numberOfLines = 0 // horizontalSeparator.backgroundColor = UIColor.whiteColor()
detailTextLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping // horizontalSeparator.alpha = 0.2
addSubview(detailTextLabel) // addSubview(horizontalSeparator)
} // }
//
private func prepareHorizontalSeparator() { // private func prepareCancelButton() {
horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false) // cancelButton.setTranslatesAutoresizingMaskIntoConstraints(false)
horizontalSeparator.backgroundColor = UIColor.whiteColor() // cancelButton.setTitle("Cancel", forState: .Normal)
horizontalSeparator.alpha = 0.2 // cancelButton.setTitleColor(buttonColor, forState: .Normal)
addSubview(horizontalSeparator) // cancelButton.pulseColor = buttonColor
} // addSubview(cancelButton)
// }
private func prepareCancelButton() { //
cancelButton.setTranslatesAutoresizingMaskIntoConstraints(false) // private func prepareOtherButton() {
cancelButton.setTitle("Cancel", forState: .Normal) // otherButton.setTranslatesAutoresizingMaskIntoConstraints(false)
cancelButton.setTitleColor(buttonColor, forState: .Normal) // otherButton.setTitle("Confirm", forState: .Normal)
cancelButton.pulseColor = buttonColor // otherButton.setTitleColor(buttonColor, forState: .Normal)
addSubview(cancelButton) // otherButton.pulseColor = buttonColor
} // addSubview(otherButton)
// }
private func prepareOtherButton() {
otherButton.setTranslatesAutoresizingMaskIntoConstraints(false)
otherButton.setTitle("Confirm", forState: .Normal)
otherButton.setTitleColor(buttonColor, forState: .Normal)
otherButton.pulseColor = buttonColor
addSubview(otherButton)
}
} }
...@@ -112,7 +112,7 @@ public class MaterialButton : UIButton { ...@@ -112,7 +112,7 @@ public class MaterialButton : UIButton {
// :name: prepareButton // :name: prepareButton
// //
internal func prepareButton() { internal func prepareButton() {
Layout.expandToParentSize(self, child: backgroundColorView) prepareBackgroundColorView()
} }
// //
...@@ -173,6 +173,7 @@ public class MaterialButton : UIButton { ...@@ -173,6 +173,7 @@ public class MaterialButton : UIButton {
backgroundColorView.clipsToBounds = true backgroundColorView.clipsToBounds = true
backgroundColorView.userInteractionEnabled = false backgroundColorView.userInteractionEnabled = false
insertSubview(backgroundColorView, atIndex: 0) insertSubview(backgroundColorView, atIndex: 0)
Layout.expandToParentSize(self, child: backgroundColorView)
} }
// //
......
...@@ -71,7 +71,6 @@ public class MaterialCard : UIView { ...@@ -71,7 +71,6 @@ public class MaterialCard : UIView {
// //
private func prepareView() { private func prepareView() {
setTranslatesAutoresizingMaskIntoConstraints(false) setTranslatesAutoresizingMaskIntoConstraints(false)
prepareBackgroundColorView()
prepareCard() prepareCard()
} }
...@@ -104,7 +103,9 @@ public class MaterialCard : UIView { ...@@ -104,7 +103,9 @@ public class MaterialCard : UIView {
// //
// :name: prepareCard // :name: prepareCard
// //
internal func prepareCard() {} internal func prepareCard() {
prepareBackgroundColorView()
}
// //
// :name: prepareShadow // :name: prepareShadow
......
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