Commit a2d32af3 by Daniel Dahan

issue-7: added titleLabel and detailTextLabel to BasicCard

parent dd56c12a
......@@ -20,67 +20,118 @@ import UIKit
import QuartzCore
public class BasicCard : MaterialCard {
public lazy var cancelButton: FlatButton = FlatButton()
public lazy var otherButton: FlatButton = FlatButton()
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()
public lazy var detailTextLabel: UILabel = UILabel()
public lazy var horizontalSeparator: UIView = UIView()
//
// :name: layoutConstraints
//
internal lazy var layoutConstraints: Array<NSLayoutConstraint> = Array<NSLayoutConstraint>()
//
// :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() {
super.prepareCard()
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]))
// deactivate and clear all constraints
NSLayoutConstraint.deactivateConstraints(layoutConstraints)
layoutConstraints.removeAll(keepCapacity: false)
// detect all components and create constraints
var verticalFormat: String = "V:|"
// title
if nil != titleLabel {
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)
titleLabel.font = Roboto.regularWithSize(22.0)
titleLabel.textColor = UIColor.whiteColor()
titleLabel.text = "Card Title"
addSubview(titleLabel)
}
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)
}
//
// 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 {
// :name: prepareButton
//
internal func prepareButton() {
Layout.expandToParentSize(self, child: backgroundColorView)
prepareBackgroundColorView()
}
//
......@@ -173,6 +173,7 @@ public class MaterialButton : UIButton {
backgroundColorView.clipsToBounds = true
backgroundColorView.userInteractionEnabled = false
insertSubview(backgroundColorView, atIndex: 0)
Layout.expandToParentSize(self, child: backgroundColorView)
}
//
......
......@@ -71,7 +71,6 @@ public class MaterialCard : UIView {
//
private func prepareView() {
setTranslatesAutoresizingMaskIntoConstraints(false)
prepareBackgroundColorView()
prepareCard()
}
......@@ -104,7 +103,9 @@ public class MaterialCard : UIView {
//
// :name: prepareCard
//
internal func prepareCard() {}
internal func prepareCard() {
prepareBackgroundColorView()
}
//
// :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