Commit b32fe056 by Daniel Dahan

issue-7: BasicCard working before divider added

parent 2416672f
...@@ -31,9 +31,16 @@ public class BasicCard : MaterialCard { ...@@ -31,9 +31,16 @@ 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: horizontalSeparator // :name: divider
// //
public lazy var horizontalSeparator: UIView = UIView() public var divider: UIView? {
didSet {
divider!.setTranslatesAutoresizingMaskIntoConstraints(false)
divider!.backgroundColor = MaterialTheme.indigo.lighten1
addSubview(divider!)
prepareCard()
}
}
/** /**
:name: titleLabel :name: titleLabel
...@@ -73,6 +80,14 @@ public class BasicCard : MaterialCard { ...@@ -73,6 +80,14 @@ public class BasicCard : MaterialCard {
} }
// //
// :name: prepareView
//
internal override func prepareView() {
super.prepareView()
backgroundColor = MaterialTheme.blueGrey.darken1
}
//
// :name: prepareCard // :name: prepareCard
// //
internal override func prepareCard() { internal override func prepareCard() {
...@@ -101,6 +116,13 @@ public class BasicCard : MaterialCard { ...@@ -101,6 +116,13 @@ public class BasicCard : MaterialCard {
} }
if nil != buttons { if nil != buttons {
// divider
if nil != divider {
// layoutConstraints += Layout.constraint("H:|-(0)-[divider(2)]-(0)-|", options: nil, metrics: nil, views: ["divider": divider!])
// views["divider"] = divider!
// verticalFormat += "-(10)-[divider]"
}
// buttons
var horizontalFormat: String = "H:|" var horizontalFormat: String = "H:|"
var buttonViews: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var buttonViews: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
for var i: Int = 0, l: Int = buttons!.count; i < l; ++i { for var i: Int = 0, l: Int = buttons!.count; i < l; ++i {
...@@ -108,21 +130,15 @@ public class BasicCard : MaterialCard { ...@@ -108,21 +130,15 @@ public class BasicCard : MaterialCard {
addSubview(button) addSubview(button)
buttonViews["button\(i)"] = button buttonViews["button\(i)"] = button
views["button\(i)"] = button as AnyObject views["button\(i)"] = button as AnyObject
horizontalFormat += "-(20)-[button\(i)]" horizontalFormat += "-(10)-[button\(i)]"
verticalFormat += "-(20)-[button\(i)]" layoutConstraints += Layout.constraint(verticalFormat + "-(5)-[button\(i)]-(10)-|", options: nil, metrics: nil, views: views)
} }
layoutConstraints += Layout.constraint(horizontalFormat, options: nil, metrics: nil, views: buttonViews) layoutConstraints += Layout.constraint(horizontalFormat, options: nil, metrics: nil, views: buttonViews)
} else {
verticalFormat += "-(10)-|"
} }
// 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 { if 0 < layoutConstraints.count {
verticalFormat += "-(20)-|"
layoutConstraints += Layout.constraint(verticalFormat, options: nil, metrics: nil, views: views) layoutConstraints += Layout.constraint(verticalFormat, options: nil, metrics: nil, views: views)
NSLayoutConstraint.activateConstraints(layoutConstraints) NSLayoutConstraint.activateConstraints(layoutConstraints)
} }
......
...@@ -116,6 +116,9 @@ public struct Layout { ...@@ -116,6 +116,9 @@ public struct Layout {
:name: constraint :name: constraint
*/ */
public static func constraint(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, AnyObject>?, views: Dictionary<String, AnyObject>) -> Array<NSLayoutConstraint> { public static func constraint(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, AnyObject>?, views: Dictionary<String, AnyObject>) -> Array<NSLayoutConstraint> {
for (_, v) in views {
v.setTranslatesAutoresizingMaskIntoConstraints(false)
}
return NSLayoutConstraint.constraintsWithVisualFormat( return NSLayoutConstraint.constraintsWithVisualFormat(
format, format,
options: options, options: options,
......
...@@ -164,7 +164,6 @@ public class MaterialCard : UIView { ...@@ -164,7 +164,6 @@ public class MaterialCard : UIView {
// We need this view so we can use the masksToBounds // We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button // so the pulse doesn't animate off the button
private func prepareBackgroundColorView() { private func prepareBackgroundColorView() {
backgroundColor = MaterialTheme.blueGrey.color
backgroundColorView.setTranslatesAutoresizingMaskIntoConstraints(false) backgroundColorView.setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColorView.layer.cornerRadius = 2 backgroundColorView.layer.cornerRadius = 2
backgroundColorView.layer.masksToBounds = true backgroundColorView.layer.masksToBounds = true
......
...@@ -368,9 +368,9 @@ public struct MaterialTheme { ...@@ -368,9 +368,9 @@ public struct MaterialTheme {
public static let lighten2: UIColor = UIColor(red: 121/255, green: 134/255, blue: 203/255, alpha: 1) public static let lighten2: UIColor = UIColor(red: 121/255, green: 134/255, blue: 203/255, alpha: 1)
public static let lighten1: UIColor = UIColor(red: 92/255, green: 107/255, blue: 192/255, alpha: 1) public static let lighten1: UIColor = UIColor(red: 92/255, green: 107/255, blue: 192/255, alpha: 1)
public static let color: UIColor = UIColor(red: 63/255, green: 81/255, blue: 181/255, alpha: 1) public static let color: UIColor = UIColor(red: 63/255, green: 81/255, blue: 181/255, alpha: 1)
public static let darken1: UIColor = UIColor(red: 57/255, green: 73/255, blue: 171/255, alpha: 1) public static let darken1: UIColor = UIColor(red: 84/255, green: 110/255, blue: 122/255, alpha: 1)
public static let darken2: UIColor = UIColor(red: 48/255, green: 63/255, blue: 159/255, alpha: 1) public static let darken2: UIColor = UIColor(red: 48/255, green: 63/255, blue: 159/255, alpha: 1)
public static let darken3: UIColor = UIColor(red: 40/255, green: 53/255, blue: 147/255, alpha: 1) public static let darken3: UIColor = UIColor(red: 55/255, green: 71/255, blue: 79/255, alpha: 1)
public static let darken4: UIColor = UIColor(red: 38/255, green: 50/255, blue: 56/255, alpha: 1) public static let darken4: UIColor = UIColor(red: 38/255, green: 50/255, blue: 56/255, alpha: 1)
public static let accent1: UIColor = UIColor(red: 140/255, green: 158/255, blue: 255/255, alpha: 1) public static let accent1: UIColor = UIColor(red: 140/255, green: 158/255, blue: 255/255, alpha: 1)
public static let accent2: UIColor = UIColor(red: 83/255, green: 109/255, blue: 254/255, alpha: 1) public static let accent2: UIColor = UIColor(red: 83/255, green: 109/255, blue: 254/255, alpha: 1)
......
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