Commit 414d067e by Daniel Dahan

updating Card views

parent c20e6381
...@@ -243,6 +243,8 @@ public class BasicCardView : MaterialPulseView { ...@@ -243,6 +243,8 @@ public class BasicCardView : MaterialPulseView {
super.prepareView() super.prepareView()
userInteractionEnabled = MaterialTheme.basicCardView.userInteractionEnabled userInteractionEnabled = MaterialTheme.basicCardView.userInteractionEnabled
backgroundColor = MaterialTheme.basicCardView.backgroundColor backgroundColor = MaterialTheme.basicCardView.backgroundColor
pulseColor = MaterialTheme.basicCardView.pulseColor
contentInsetsRef = MaterialTheme.basicCardView.contentInsetsRef contentInsetsRef = MaterialTheme.basicCardView.contentInsetsRef
titleLabelInsetsRef = MaterialTheme.basicCardView.titleLabelInsetsRef titleLabelInsetsRef = MaterialTheme.basicCardView.titleLabelInsetsRef
detailLabelInsetsRef = MaterialTheme.basicCardView.detailLabelInsetsRef detailLabelInsetsRef = MaterialTheme.basicCardView.detailLabelInsetsRef
...@@ -287,15 +289,18 @@ public class BasicCardView : MaterialPulseView { ...@@ -287,15 +289,18 @@ public class BasicCardView : MaterialPulseView {
// title // title
if let v = titleLabel { if let v = titleLabel {
addSubview(v)
verticalFormat += "-[titleLabel]" verticalFormat += "-[titleLabel]"
views["titleLabel"] = v views["titleLabel"] = v
addSubview(v)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + titleLabelInsetsRef!.left, right: contentInsetsRef!.right + titleLabelInsetsRef!.right) MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + titleLabelInsetsRef!.left, right: contentInsetsRef!.right + titleLabelInsetsRef!.right)
} }
// detail // detail
if let v = detailLabel { if let v = detailLabel {
addSubview(v)
if nil != titleLabel { if nil != titleLabel {
verticalFormat += "-(insetB)" verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInsetsRef!.bottom + detailLabelInsetsRef!.top metrics["insetB"] = titleLabelInsetsRef!.bottom + detailLabelInsetsRef!.top
...@@ -303,8 +308,7 @@ public class BasicCardView : MaterialPulseView { ...@@ -303,8 +308,7 @@ public class BasicCardView : MaterialPulseView {
verticalFormat += "-[detailLabel]" verticalFormat += "-[detailLabel]"
views["detailLabel"] = v views["detailLabel"] = v
addSubview(v)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + detailLabelInsetsRef!.left, right: contentInsetsRef!.right + detailLabelInsetsRef!.right) MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + detailLabelInsetsRef!.left, right: contentInsetsRef!.right + detailLabelInsetsRef!.right)
} }
...@@ -387,10 +391,13 @@ public class BasicCardView : MaterialPulseView { ...@@ -387,10 +391,13 @@ public class BasicCardView : MaterialPulseView {
} else { } else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + titleLabelInsetsRef!.bottom metrics["insetC"] = (metrics["insetC"] as! CGFloat) + titleLabelInsetsRef!.bottom
} }
} else if nil != metrics["insetC"] {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInsetsRef!.top
} }
if 0 < views.count { if 0 < views.count {
verticalFormat += "-(insetBottom)-|" verticalFormat += "-(insetBottom)-|"
print(verticalFormat)
addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views)) addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views))
} }
} }
......
...@@ -34,8 +34,12 @@ public class ImageCardView : MaterialPulseView { ...@@ -34,8 +34,12 @@ public class ImageCardView : MaterialPulseView {
set(value) { set(value) {
if let v = value { if let v = value {
imageLayer.contents = v.CGImage imageLayer.contents = v.CGImage
if 0 == imageLayer.frame.size.height { if 0 == maxImageSize {
imageLayer.frame.size.height = v.size.height if 0 == imageLayer.frame.size.height {
imageLayer.frame.size.height = v.size.height
}
} else {
imageLayer.frame.size.height = maxImageSize
} }
imageLayer.hidden = false imageLayer.hidden = false
} }
...@@ -49,6 +53,19 @@ public class ImageCardView : MaterialPulseView { ...@@ -49,6 +53,19 @@ public class ImageCardView : MaterialPulseView {
} }
/** /**
:name: maxImageSize
*/
public var maxImageSize: CGFloat = 0 {
didSet {
if 0 < maxImageSize {
imageLayer.frame.size.height = maxImageSize
// imageLayer.contentsGravity = MaterialGravityToString(contentsGravity)
}
reloadView()
}
}
/**
:name: contentsRect :name: contentsRect
*/ */
public override var contentsRect: CGRect { public override var contentsRect: CGRect {
...@@ -299,11 +316,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -299,11 +316,7 @@ public class ImageCardView : MaterialPulseView {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
// image // image
let h: CGFloat = imageLayer.frame.size.height imageLayer.frame.size.width = bounds.size.width
imageLayer.frame = bounds
if 0 < h && nil != imageLayer.contents {
imageLayer.frame.size.height = h
}
// divider // divider
if true == divider { if true == divider {
...@@ -329,6 +342,8 @@ public class ImageCardView : MaterialPulseView { ...@@ -329,6 +342,8 @@ public class ImageCardView : MaterialPulseView {
super.prepareView() super.prepareView()
userInteractionEnabled = MaterialTheme.imageCardView.userInteractionEnabled userInteractionEnabled = MaterialTheme.imageCardView.userInteractionEnabled
backgroundColor = MaterialTheme.imageCardView.backgroundColor backgroundColor = MaterialTheme.imageCardView.backgroundColor
pulseColor = MaterialTheme.imageCardView.pulseColor
contentInsetsRef = MaterialTheme.imageCardView.contentInsetsRef contentInsetsRef = MaterialTheme.imageCardView.contentInsetsRef
titleLabelInsetsRef = MaterialTheme.imageCardView.titleLabelInsetsRef titleLabelInsetsRef = MaterialTheme.imageCardView.titleLabelInsetsRef
detailLabelInsetsRef = MaterialTheme.imageCardView.detailLabelInsetsRef detailLabelInsetsRef = MaterialTheme.imageCardView.detailLabelInsetsRef
...@@ -367,7 +382,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -367,7 +382,7 @@ public class ImageCardView : MaterialPulseView {
if nil != imageLayer.contents { if nil != imageLayer.contents {
verticalFormat += "-(insetTop)" verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef!.top + imageLayer.frame.size.height metrics["insetTop"] = imageLayer.frame.size.height
} else if nil != titleLabel { } else if nil != titleLabel {
verticalFormat += "-(insetTop)" verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef!.top + titleLabelInsetsRef!.top metrics["insetTop"] = contentInsetsRef!.top + titleLabelInsetsRef!.top
...@@ -379,6 +394,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -379,6 +394,7 @@ public class ImageCardView : MaterialPulseView {
// title // title
if let v = titleLabel { if let v = titleLabel {
addSubview(v) addSubview(v)
if nil == imageLayer.contents { if nil == imageLayer.contents {
verticalFormat += "-[titleLabel]" verticalFormat += "-[titleLabel]"
views["titleLabel"] = v views["titleLabel"] = v
...@@ -390,15 +406,18 @@ public class ImageCardView : MaterialPulseView { ...@@ -390,15 +406,18 @@ public class ImageCardView : MaterialPulseView {
// detail // detail
if let v = detailLabel { if let v = detailLabel {
addSubview(v)
if nil == imageLayer.contents && nil != titleLabel { if nil == imageLayer.contents && nil != titleLabel {
verticalFormat += "-(insetB)" verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInsetsRef!.bottom + detailLabelInsetsRef!.top metrics["insetB"] = titleLabelInsetsRef!.bottom + detailLabelInsetsRef!.top
} else {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + detailLabelInsetsRef!.top
} }
verticalFormat += "-[detailLabel]" verticalFormat += "-[detailLabel]"
views["detailLabel"] = v views["detailLabel"] = v
addSubview(v)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + detailLabelInsetsRef!.left, right: contentInsetsRef!.right + detailLabelInsetsRef!.right) MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + detailLabelInsetsRef!.left, right: contentInsetsRef!.right + detailLabelInsetsRef!.right)
} }
...@@ -481,10 +500,13 @@ public class ImageCardView : MaterialPulseView { ...@@ -481,10 +500,13 @@ public class ImageCardView : MaterialPulseView {
} else { } else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + titleLabelInsetsRef!.bottom metrics["insetC"] = (metrics["insetC"] as! CGFloat) + titleLabelInsetsRef!.bottom
} }
} else if nil != metrics["insetC"] {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInsetsRef!.top
} }
if 0 < views.count { if 0 < views.count {
verticalFormat += "-(insetBottom)-|" verticalFormat += "-(insetBottom)-|"
print(verticalFormat)
addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views)) addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views))
} }
} }
...@@ -493,7 +515,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -493,7 +515,7 @@ public class ImageCardView : MaterialPulseView {
// :name: prepareImageLayer // :name: prepareImageLayer
// //
internal func prepareImageLayer() { internal func prepareImageLayer() {
imageLayer = CAShapeLayer() imageLayer.masksToBounds = true
imageLayer.zPosition = 0 imageLayer.zPosition = 0
visualLayer.addSublayer(imageLayer) visualLayer.addSublayer(imageLayer)
} }
......
...@@ -62,10 +62,10 @@ public enum MaterialInsets { ...@@ -62,10 +62,10 @@ public enum MaterialInsets {
*/ */
public func MaterialInsetsToValue(inset: MaterialInsets) -> MaterialInsetsType { public func MaterialInsetsToValue(inset: MaterialInsets) -> MaterialInsetsType {
switch inset { switch inset {
// square
case .None: case .None:
return (top: 0, left: 0, bottom: 0, right: 0) return (top: 0, left: 0, bottom: 0, right: 0)
// square
case .Square1: case .Square1:
return (top: 4, left: 4, bottom: 4, right: 4) return (top: 4, left: 4, bottom: 4, right: 4)
case .Square2: case .Square2:
......
...@@ -102,11 +102,11 @@ public extension MaterialTheme.basicCardView { ...@@ -102,11 +102,11 @@ public extension MaterialTheme.basicCardView {
// shape // shape
public static var masksToBounds: Bool = true public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = .None public static var cornerRadius: MaterialRadius = .None
public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square3) public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2) public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var detailLabelInsetsRef: MaterialInsetsType = (top: 0, left: 8, bottom: 16, right: 8) public static var detailLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var leftButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 8, bottom: -8, right: 0) public static var leftButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.None)
public static var rightButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: -8, right: 8) public static var rightButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.None)
// border // border
public static var borderWidth: MaterialBorder = .None public static var borderWidth: MaterialBorder = .None
...@@ -114,7 +114,7 @@ public extension MaterialTheme.basicCardView { ...@@ -114,7 +114,7 @@ public extension MaterialTheme.basicCardView {
// color // color
public static var backgroundColor: UIColor = MaterialColor.white public static var backgroundColor: UIColor = MaterialColor.white
public static var pulseColor: UIColor = MaterialColor.white public static var pulseColor: UIColor = MaterialColor.blueGrey.lighten4
public static var pulseColorOpacity: CGFloat = 0.25 public static var pulseColorOpacity: CGFloat = 0.25
// interaction // interaction
...@@ -144,10 +144,10 @@ public extension MaterialTheme.imageCardView { ...@@ -144,10 +144,10 @@ public extension MaterialTheme.imageCardView {
public static var masksToBounds: Bool = true public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = .None public static var cornerRadius: MaterialRadius = .None
public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2) public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var titleLabelInsetsRef: MaterialInsetsType = (top: 8, left: 16, bottom: 0, right: 16) public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var detailLabelInsetsRef: MaterialInsetsType = (top: 8, left: 16, bottom: 16, right: 16) public static var detailLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var leftButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: 0, right: 0) public static var leftButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.None)
public static var rightButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: 0, right: 0) public static var rightButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.None)
// border // border
public static var borderWidth: MaterialBorder = .None public static var borderWidth: MaterialBorder = .None
...@@ -155,7 +155,7 @@ public extension MaterialTheme.imageCardView { ...@@ -155,7 +155,7 @@ public extension MaterialTheme.imageCardView {
// color // color
public static var backgroundColor: UIColor = MaterialColor.white public static var backgroundColor: UIColor = MaterialColor.white
public static var pulseColor: UIColor = MaterialColor.white public static var pulseColor: UIColor = MaterialColor.blueGrey.lighten4
public static var pulseColorOpacity: CGFloat = 0.25 public static var pulseColorOpacity: CGFloat = 0.25
// interaction // interaction
......
...@@ -282,13 +282,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -282,13 +282,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
internal func prepareLeftView() { internal func prepareLeftView() {
prepareContainer(&leftViewContainer, originX: leftOriginX, originY: 0, width: options.leftViewContainerWidth, height: view.bounds.size.height) prepareContainer(&leftViewContainer, originX: leftOriginX, originY: 0, width: options.leftViewContainerWidth, height: view.bounds.size.height)
prepareLeftGestures() prepareLeftGestures()
// leftViewContainer!.layer.speed = 0
let w: CGFloat = leftViewContainer!.width
let h: CGFloat = leftViewContainer!.height
// leftAnimation = MaterialAnimation.position(CGPointMake(w / 2, h / 2), duration: 1)
// leftViewContainer!.position = CGPointMake(-(w / 2), h / 2)
// leftViewContainer!.animation(leftAnimation!)
} }
// //
......
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