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()
prepareHorizontalSeparator()
prepareCancelButton()
prepareOtherButton()
addConstraints(Layout.constraint("H:|-(20)-[titleLabel]-(20)-|", options: nil, metrics: nil, views: ["titleLabel": titleLabel]))
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]))
}
private func prepareTitleLabel() { // deactivate and clear all constraints
titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false) NSLayoutConstraint.deactivateConstraints(layoutConstraints)
titleLabel.font = Roboto.regularWithSize(22.0) layoutConstraints.removeAll(keepCapacity: false)
titleLabel.textColor = UIColor.whiteColor()
titleLabel.text = "Card Title"
addSubview(titleLabel)
}
private func prepareDetailTextLabel() { // detect all components and create constraints
detailTextLabel.setTranslatesAutoresizingMaskIntoConstraints(false) var verticalFormat: String = "V:|"
detailTextLabel.font = Roboto.lightWithSize(16.0)
detailTextLabel.textColor = UIColor.whiteColor()
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
addSubview(detailTextLabel)
}
private func prepareHorizontalSeparator() { // title
horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false) if nil != titleLabel {
horizontalSeparator.backgroundColor = UIColor.whiteColor() layoutConstraints += Layout.constraint("H:|-(20)-[titleLabel]-(20)-|", options: nil, metrics: nil, views: ["titleLabel": titleLabel!])
horizontalSeparator.alpha = 0.2 verticalFormat += "-(20)-[titleLabel(22)]"
addSubview(horizontalSeparator) views["titleLabel"] = titleLabel!
} }
private func prepareCancelButton() { // details
cancelButton.setTranslatesAutoresizingMaskIntoConstraints(false) if nil != detailTextLabel {
cancelButton.setTitle("Cancel", forState: .Normal) layoutConstraints += Layout.constraint("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: ["detailTextLabel": detailTextLabel!])
cancelButton.setTitleColor(buttonColor, forState: .Normal) verticalFormat += "-(20)-[detailTextLabel]"
cancelButton.pulseColor = buttonColor views["detailTextLabel"] = detailTextLabel!
addSubview(cancelButton)
} }
private func prepareOtherButton() { // addConstraints(Layout.constraint("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: ["detailTextLabel": detailTextLabel]))
otherButton.setTranslatesAutoresizingMaskIntoConstraints(false) // addConstraints(Layout.constraint("H:|[horizontalSeparator]|", options: nil, metrics: nil, views: ["horizontalSeparator": horizontalSeparator]))
otherButton.setTitle("Confirm", forState: .Normal) // addConstraints(Layout.constraint("H:|-(10)-[cancelButton(80)]-(10)-[otherButton(80)]", options: nil, metrics: nil, views: ["cancelButton": cancelButton, "otherButton": otherButton]))
otherButton.setTitleColor(buttonColor, forState: .Normal) // 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]))
otherButton.pulseColor = buttonColor // 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]))
addSubview(otherButton)
if 0 < layoutConstraints.count {
verticalFormat += "-(20)-|"
layoutConstraints += Layout.constraint(verticalFormat, options: nil, metrics: nil, views: views)
NSLayoutConstraint.activateConstraints(layoutConstraints)
} }
}
//
// private func prepareDetailTextLabel() {
// detailTextLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
// detailTextLabel.font = Roboto.lightWithSize(16.0)
// detailTextLabel.textColor = UIColor.whiteColor()
// 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
// addSubview(detailTextLabel)
// }
//
// private func prepareHorizontalSeparator() {
// horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false)
// horizontalSeparator.backgroundColor = UIColor.whiteColor()
// horizontalSeparator.alpha = 0.2
// addSubview(horizontalSeparator)
// }
//
// private func prepareCancelButton() {
// cancelButton.setTranslatesAutoresizingMaskIntoConstraints(false)
// cancelButton.setTitle("Cancel", forState: .Normal)
// cancelButton.setTitleColor(buttonColor, forState: .Normal)
// cancelButton.pulseColor = buttonColor
// addSubview(cancelButton)
// }
//
// 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