Commit ffcb12a1 by Daniel Dahan

BasicCardView added

parent 62c42c52
...@@ -20,20 +20,39 @@ import UIKit ...@@ -20,20 +20,39 @@ import UIKit
public class BasicCardView: MaterialPulseView { public class BasicCardView: MaterialPulseView {
/** /**
:name: titleInsets :name: contentInsets
*/ */
public var titleInsets: MaterialInsets? { public var contentInsets: MaterialInsets? {
didSet { didSet {
titleInsetsRef = nil == titleInsets ? nil : MaterialInsetsToValue(titleInsets!) contentInsetsRef = nil == contentInsets ? nil : MaterialInsetsToValue(contentInsets!)
} }
} }
/** /**
:name: titleInsetsRef :name: contentInsetsRef
*/ */
public var titleInsetsRef: MaterialInsetsType! { public var contentInsetsRef: MaterialInsetsType! {
didSet { didSet {
titleInsetsRef = nil == titleInsetsRef ? (top: 0, left: 0, bottom: 0, right: 0) : titleInsetsRef! contentInsetsRef = nil == contentInsetsRef ? (top: 0, left: 0, bottom: 0, right: 0) : contentInsetsRef!
reloadView()
}
}
/**
:name: titleLabelInsets
*/
public var titleLabelInsets: MaterialInsets? {
didSet {
titleLabelInsetsRef = nil == titleLabelInsets ? nil : MaterialInsetsToValue(titleLabelInsets!)
}
}
/**
:name: titleLabelInsetsRef
*/
public var titleLabelInsetsRef: MaterialInsetsType! {
didSet {
titleLabelInsetsRef = nil == titleLabelInsetsRef ? (top: 0, left: 0, bottom: 0, right: 0) : titleLabelInsetsRef!
reloadView() reloadView()
} }
} }
...@@ -51,6 +70,37 @@ public class BasicCardView: MaterialPulseView { ...@@ -51,6 +70,37 @@ public class BasicCardView: MaterialPulseView {
} }
/** /**
:name: detailLabelInsets
*/
public var detailLabelInsets: MaterialInsets? {
didSet {
detailLabelInsetsRef = nil == detailLabelInsets ? nil : MaterialInsetsToValue(detailLabelInsets!)
}
}
/**
:name: detailLabelInsetsRef
*/
public var detailLabelInsetsRef: MaterialInsetsType! {
didSet {
detailLabelInsetsRef = nil == detailLabelInsetsRef ? (top: 0, left: 0, bottom: 0, right: 0) : detailLabelInsetsRef!
reloadView()
}
}
/**
:name: detailLabel
*/
public var detailLabel: UILabel? {
didSet {
if let v = detailLabel {
v.translatesAutoresizingMaskIntoConstraints = false
}
reloadView()
}
}
/**
:name: leftButtonsInsets :name: leftButtonsInsets
*/ */
public var leftButtonsInsets: MaterialInsets? { public var leftButtonsInsets: MaterialInsets? {
...@@ -140,9 +190,9 @@ public class BasicCardView: MaterialPulseView { ...@@ -140,9 +190,9 @@ public class BasicCardView: MaterialPulseView {
/** /**
:name: init :name: init
*/ */
public convenience init?(titleLabel: UILabel? = nil, leftButtons: Array<MaterialButton>? = nil, rightButtons: Array<MaterialButton>? = nil) { public convenience init?(titleLabel: UILabel? = nil, detailLabel: UILabel? = nil, leftButtons: Array<MaterialButton>? = nil, rightButtons: Array<MaterialButton>? = nil) {
self.init(frame: CGRectZero) self.init(frame: CGRectZero)
self.prepareProperties(titleLabel, leftButtons: leftButtons, rightButtons: rightButtons) self.prepareProperties(titleLabel, detailLabel: detailLabel, leftButtons: leftButtons, rightButtons: rightButtons)
} }
/** /**
...@@ -155,20 +205,37 @@ public class BasicCardView: MaterialPulseView { ...@@ -155,20 +205,37 @@ public class BasicCardView: MaterialPulseView {
v.removeFromSuperview() v.removeFromSuperview()
} }
var verticalFormat: String = "V:|" var verticalFormat: String = "V:|-(insetTop)"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var metrics: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var metrics: Dictionary<String, AnyObject> = ["insetTop": contentInsetsRef!.top, "insetBottom": contentInsetsRef!.bottom]
// title // title
if let v = titleLabel { if let v = titleLabel {
verticalFormat += "-(titleLabelTopInset)-[titleLabel]-(titleLabelBottomInset)-" verticalFormat += "-[titleLabel]"
views["titleLabel"] = titleLabel views["titleLabel"] = v
metrics["titleLabelTopInset"] = titleInsetsRef!.top
metrics["titleLabelBottomInset"] = titleInsetsRef!.bottom metrics["insetTop"] = titleLabelInsetsRef!.top
addSubview(v) addSubview(v)
v.layer.zPosition = 2000 v.layer.zPosition = 2000
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: titleInsetsRef!.left, right: titleInsetsRef!.right) MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + titleLabelInsetsRef!.left, right: contentInsetsRef!.right + titleLabelInsetsRef!.right)
}
// detail
if let v = detailLabel {
if nil == titleLabel {
metrics["insetTop"] = detailLabelInsetsRef!.top
} else {
verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInsetsRef!.bottom + detailLabelInsetsRef!.top
}
verticalFormat += "-[detailLabel]"
views["detailLabel"] = v
addSubview(v)
v.layer.zPosition = 2000
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + detailLabelInsetsRef!.left, right: contentInsetsRef!.right + detailLabelInsetsRef!.right)
} }
// leftButtons // leftButtons
...@@ -207,8 +274,20 @@ public class BasicCardView: MaterialPulseView { ...@@ -207,8 +274,20 @@ public class BasicCardView: MaterialPulseView {
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : rightButtonsInsetsRef!.right], views: d)) addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : rightButtonsInsetsRef!.right], views: d))
} }
if nil != titleLabel {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + titleLabelInsetsRef!.top
} else if nil != detailLabel {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + detailLabelInsetsRef!.top
}
if nil != detailLabel {
metrics["insetBottom"] = (metrics["insetBottom"] as! CGFloat) + detailLabelInsetsRef!.bottom
} else if nil != titleLabel {
metrics["insetBottom"] = (metrics["insetBottom"] as! CGFloat) + titleLabelInsetsRef!.bottom
}
if 0 < views.count { if 0 < views.count {
verticalFormat += "|" verticalFormat += "-(insetBottom)-|"
addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views)) addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views))
} }
...@@ -217,8 +296,9 @@ public class BasicCardView: MaterialPulseView { ...@@ -217,8 +296,9 @@ public class BasicCardView: MaterialPulseView {
// //
// :name: prepareProperties // :name: prepareProperties
// //
internal func prepareProperties(titleLabel: UILabel?, leftButtons: Array<MaterialButton>?, rightButtons: Array<MaterialButton>?) { internal func prepareProperties(titleLabel: UILabel?, detailLabel: UILabel?, leftButtons: Array<MaterialButton>?, rightButtons: Array<MaterialButton>?) {
self.titleLabel = titleLabel self.titleLabel = titleLabel
self.detailLabel = detailLabel
self.leftButtons = leftButtons self.leftButtons = leftButtons
self.rightButtons = rightButtons self.rightButtons = rightButtons
} }
...@@ -230,7 +310,9 @@ public class BasicCardView: MaterialPulseView { ...@@ -230,7 +310,9 @@ public class BasicCardView: MaterialPulseView {
super.prepareView() super.prepareView()
userInteractionEnabled = MaterialTheme.basicCardView.userInteractionEnabled userInteractionEnabled = MaterialTheme.basicCardView.userInteractionEnabled
backgroundColor = MaterialTheme.basicCardView.backgroudColor backgroundColor = MaterialTheme.basicCardView.backgroudColor
titleInsetsRef = MaterialTheme.basicCardView.titleInsetsRef contentInsetsRef = MaterialTheme.basicCardView.contentInsetsRef
titleLabelInsetsRef = MaterialTheme.basicCardView.titleLabelInsetsRef
detailLabelInsetsRef = MaterialTheme.basicCardView.detailLabelInsetsRef
leftButtonsInsetsRef = MaterialTheme.basicCardView.leftButtonsInsetsRef leftButtonsInsetsRef = MaterialTheme.basicCardView.leftButtonsInsetsRef
rightButtonsInsetsRef = MaterialTheme.basicCardView.rightButtonsInsetsRef rightButtonsInsetsRef = MaterialTheme.basicCardView.rightButtonsInsetsRef
......
...@@ -118,7 +118,9 @@ public extension MaterialTheme.basicCardView { ...@@ -118,7 +118,9 @@ public extension MaterialTheme.basicCardView {
// shape // shape
public static var masksToBounds: Bool = true public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = MaterialTheme.view.cornerRadius public static var cornerRadius: MaterialRadius = MaterialTheme.view.cornerRadius
public static var titleInsetsRef: MaterialInsetsType = (top: 0, left: 8, bottom: 10, right: 8) public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var detailLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var leftButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2) public static var leftButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var rightButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2) public static var rightButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
...@@ -159,7 +161,8 @@ public extension MaterialTheme.navigationBarView { ...@@ -159,7 +161,8 @@ public extension MaterialTheme.navigationBarView {
// shape // shape
public static var masksToBounds: Bool = MaterialTheme.view.masksToBounds public static var masksToBounds: Bool = MaterialTheme.view.masksToBounds
public static var cornerRadius: MaterialRadius = MaterialTheme.view.cornerRadius public static var cornerRadius: MaterialRadius = MaterialTheme.view.cornerRadius
public static var titleInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2) public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var leftButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2) public static var leftButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var rightButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2) public static var rightButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
......
...@@ -29,20 +29,20 @@ public class NavigationBarView: MaterialView { ...@@ -29,20 +29,20 @@ public class NavigationBarView: MaterialView {
} }
/** /**
:name: titleInsets :name: titleLabelInsets
*/ */
public var titleInsets: MaterialInsets? { public var titleLabelInsets: MaterialInsets? {
didSet { didSet {
titleInsetsRef = nil == titleInsets ? nil : MaterialInsetsToValue(titleInsets!) titleLabelInsetsRef = nil == titleLabelInsets ? nil : MaterialInsetsToValue(titleLabelInsets!)
} }
} }
/** /**
:name: titleInsetsRef :name: titleLabelInsetsRef
*/ */
public var titleInsetsRef: MaterialInsetsType! { public var titleLabelInsetsRef: MaterialInsetsType! {
didSet { didSet {
titleInsetsRef = nil == titleInsetsRef ? (top: 0, left: 0, bottom: 0, right: 0) : titleInsetsRef! titleLabelInsetsRef = nil == titleLabelInsetsRef ? (top: 0, left: 0, bottom: 0, right: 0) : titleLabelInsetsRef!
reloadView() reloadView()
} }
} }
...@@ -184,8 +184,8 @@ public class NavigationBarView: MaterialView { ...@@ -184,8 +184,8 @@ public class NavigationBarView: MaterialView {
// title // title
if let v = titleLabel { if let v = titleLabel {
insertSubview(v, atIndex: 0) insertSubview(v, atIndex: 0)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: titleInsetsRef!.left, right: titleInsetsRef!.right) MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: titleLabelInsetsRef!.left, right: titleLabelInsetsRef!.right)
MaterialLayout.alignFromBottom(self, child: v, bottom: titleInsetsRef!.bottom) MaterialLayout.alignFromBottom(self, child: v, bottom: titleLabelInsetsRef!.bottom)
} }
// rightButtons // rightButtons
...@@ -224,7 +224,7 @@ public class NavigationBarView: MaterialView { ...@@ -224,7 +224,7 @@ public class NavigationBarView: MaterialView {
userInteractionEnabled = MaterialTheme.navigationBarView.userInteractionEnabled userInteractionEnabled = MaterialTheme.navigationBarView.userInteractionEnabled
backgroundColor = MaterialTheme.navigationBarView.backgroudColor backgroundColor = MaterialTheme.navigationBarView.backgroudColor
statusBarStyle = MaterialTheme.navigationBarView.statusBarStyle statusBarStyle = MaterialTheme.navigationBarView.statusBarStyle
titleInsetsRef = MaterialTheme.navigationBarView.titleInsetsRef titleLabelInsetsRef = MaterialTheme.navigationBarView.titleLabelInsetsRef
leftButtonsInsetsRef = MaterialTheme.navigationBarView.leftButtonsInsetsRef leftButtonsInsetsRef = MaterialTheme.navigationBarView.leftButtonsInsetsRef
rightButtonsInsetsRef = MaterialTheme.navigationBarView.rightButtonsInsetsRef rightButtonsInsetsRef = MaterialTheme.navigationBarView.rightButtonsInsetsRef
......
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