Commit 3d4b16ac by Daniel Dahan

initial setup for ImageCardView

parent 09446a7f
...@@ -20,6 +20,107 @@ import UIKit ...@@ -20,6 +20,107 @@ import UIKit
public class ImageCardView : MaterialPulseView { public class ImageCardView : MaterialPulseView {
// //
// :name: imageLayer
//
public private(set) var imageLayer: CAShapeLayer?
/**
:name: image
*/
public override var image: UIImage? {
get {
return nil == imageLayer?.contents ? nil : UIImage(CGImage: imageLayer!.contents as! CGImage)
}
set(value) {
if let v = value {
prepareImageLayer()
imageLayer!.contents = v.CGImage
if 0 == imageLayer!.frame.size.height {
imageLayer!.frame.size.height = 200
}
}
else {
imageLayer?.frame = CGRectZero
imageLayer?.removeFromSuperlayer()
imageLayer = nil
}
reloadView()
}
}
/**
:name: contentsRect
*/
public override var contentsRect: CGRect {
didSet {
prepareImageLayer()
if let v = imageLayer {
v.contentsRect = contentsRect
if nil != imageLayer?.contents {
reloadView()
}
}
}
}
/**
:name: contentsCenter
*/
public override var contentsCenter: CGRect {
didSet {
prepareImageLayer()
if let v = imageLayer {
v.contentsCenter = contentsCenter
if nil != imageLayer?.contents {
reloadView()
}
}
}
}
/**
:name: contentsScale
*/
public override var contentsScale: CGFloat {
didSet {
prepareImageLayer()
if let v = imageLayer {
v.contentsScale = contentsScale
if nil != imageLayer?.contents {
reloadView()
}
}
}
}
/**
:name: contentsGravity
*/
public override var contentsGravity: MaterialGravity {
didSet {
prepareImageLayer()
if let v = imageLayer {
v.contentsGravity = MaterialGravityToString(contentsGravity)
if nil != imageLayer?.contents {
reloadView()
}
}
}
}
/**
:name: masksToBounds
*/
public override var masksToBounds: Bool {
get {
return nil == imageLayer?.masksToBounds ? false : imageLayer!.masksToBounds
}
set(value) {
imageLayer?.masksToBounds = value
}
}
//
// :name: dividerLayer // :name: dividerLayer
// //
internal var dividerLayer: CAShapeLayer? internal var dividerLayer: CAShapeLayer?
...@@ -220,6 +321,13 @@ public class ImageCardView : MaterialPulseView { ...@@ -220,6 +321,13 @@ public class ImageCardView : MaterialPulseView {
*/ */
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
// image
let h: CGFloat? = imageLayer?.frame.size.height
imageLayer?.frame = bounds
if 0 < h {
imageLayer?.frame.size.height = h!
}
// divider // divider
if true == divider { if true == divider {
var y: CGFloat = 0 var y: CGFloat = 0
...@@ -259,6 +367,12 @@ public class ImageCardView : MaterialPulseView { ...@@ -259,6 +367,12 @@ public class ImageCardView : MaterialPulseView {
metrics["insetTop"] = contentInsetsRef!.top + detailLabelInsetsRef!.top metrics["insetTop"] = contentInsetsRef!.top + detailLabelInsetsRef!.top
} }
// image
if 0 < imageLayer?.frame.size.height {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + imageLayer!.frame.size.height - (nil == titleLabel ? 0 : titleLabel!.frame.size.height)
print(titleLabel!.frame.size.height)
}
// title // title
if let v = titleLabel { if let v = titleLabel {
verticalFormat += "-[titleLabel]" verticalFormat += "-[titleLabel]"
...@@ -370,6 +484,17 @@ public class ImageCardView : MaterialPulseView { ...@@ -370,6 +484,17 @@ public class ImageCardView : MaterialPulseView {
} }
// //
// :name: prepareImageLayer
//
internal func prepareImageLayer() {
if nil == imageLayer {
imageLayer = CAShapeLayer()
imageLayer!.zPosition = 0
visualLayer.addSublayer(imageLayer!)
}
}
//
// :name: prepareDivider // :name: prepareDivider
// //
internal func prepareDivider(y: CGFloat, width: CGFloat) { internal func prepareDivider(y: CGFloat, width: CGFloat) {
...@@ -417,5 +542,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -417,5 +542,7 @@ public class ImageCardView : MaterialPulseView {
borderWidth = MaterialTheme.imageCardView.borderWidth borderWidth = MaterialTheme.imageCardView.borderWidth
borderColor = MaterialTheme.imageCardView.bordercolor borderColor = MaterialTheme.imageCardView.bordercolor
dividerColor = MaterialTheme.imageCardView.dividerColor dividerColor = MaterialTheme.imageCardView.dividerColor
visualLayer.masksToBounds = true
} }
} }
...@@ -88,10 +88,10 @@ public class MaterialButton : UIButton { ...@@ -88,10 +88,10 @@ public class MaterialButton : UIButton {
*/ */
public var x: CGFloat { public var x: CGFloat {
get { get {
return layer.frame.origin.x return frame.origin.x
} }
set(value) { set(value) {
layer.frame.origin.x = value frame.origin.x = value
} }
} }
...@@ -100,10 +100,10 @@ public class MaterialButton : UIButton { ...@@ -100,10 +100,10 @@ public class MaterialButton : UIButton {
*/ */
public var y: CGFloat { public var y: CGFloat {
get { get {
return layer.frame.origin.y return frame.origin.y
} }
set(value) { set(value) {
layer.frame.origin.y = value frame.origin.y = value
} }
} }
...@@ -112,12 +112,12 @@ public class MaterialButton : UIButton { ...@@ -112,12 +112,12 @@ public class MaterialButton : UIButton {
*/ */
public var width: CGFloat { public var width: CGFloat {
get { get {
return layer.frame.size.width return frame.size.width
} }
set(value) { set(value) {
layer.frame.size.width = value frame.size.width = value
if .None != shape { if .None != shape {
layer.frame.size.height = value frame.size.height = value
} }
} }
} }
...@@ -127,12 +127,12 @@ public class MaterialButton : UIButton { ...@@ -127,12 +127,12 @@ public class MaterialButton : UIButton {
*/ */
public var height: CGFloat { public var height: CGFloat {
get { get {
return layer.frame.size.height return frame.size.height
} }
set(value) { set(value) {
layer.frame.size.height = value frame.size.height = value
if .None != shape { if .None != shape {
layer.frame.size.width = value frame.size.width = value
} }
} }
} }
...@@ -215,9 +215,9 @@ public class MaterialButton : UIButton { ...@@ -215,9 +215,9 @@ public class MaterialButton : UIButton {
didSet { didSet {
if .None != shape { if .None != shape {
if width < height { if width < height {
layer.frame.size.width = height frame.size.width = height
} else { } else {
layer.frame.size.height = width frame.size.height = width
} }
} }
} }
......
...@@ -143,8 +143,8 @@ public extension MaterialTheme.imageCardView { ...@@ -143,8 +143,8 @@ 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(.Square3) public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square3)
public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2) public static var titleLabelInsetsRef: MaterialInsetsType = (top: 0, left: 0, bottom: 0, right: 0)
public static var detailLabelInsetsRef: MaterialInsetsType = (top: 0, left: 8, bottom: 16, right: 8) public static var detailLabelInsetsRef: MaterialInsetsType = (top: 16, left: 8, bottom: 16, right: 8)
public static var leftButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 8, bottom: -8, right: 0) public static var leftButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 8, bottom: -8, right: 0)
public static var rightButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: -8, right: 8) public static var rightButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: -8, right: 8)
......
...@@ -70,6 +70,18 @@ public class MaterialView : UIView { ...@@ -70,6 +70,18 @@ public class MaterialView : UIView {
} }
/** /**
:name: masksToBounds
*/
public var masksToBounds: Bool {
get {
return visualLayer.masksToBounds
}
set(value) {
visualLayer.masksToBounds = value
}
}
/**
:name: backgroundColor :name: backgroundColor
*/ */
public override var backgroundColor: UIColor? { public override var backgroundColor: UIColor? {
...@@ -83,10 +95,10 @@ public class MaterialView : UIView { ...@@ -83,10 +95,10 @@ public class MaterialView : UIView {
*/ */
public var x: CGFloat { public var x: CGFloat {
get { get {
return layer.frame.origin.x return frame.origin.x
} }
set(value) { set(value) {
layer.frame.origin.x = value frame.origin.x = value
} }
} }
...@@ -95,10 +107,10 @@ public class MaterialView : UIView { ...@@ -95,10 +107,10 @@ public class MaterialView : UIView {
*/ */
public var y: CGFloat { public var y: CGFloat {
get { get {
return layer.frame.origin.y return frame.origin.y
} }
set(value) { set(value) {
layer.frame.origin.y = value frame.origin.y = value
} }
} }
...@@ -107,12 +119,12 @@ public class MaterialView : UIView { ...@@ -107,12 +119,12 @@ public class MaterialView : UIView {
*/ */
public var width: CGFloat { public var width: CGFloat {
get { get {
return layer.frame.size.width return frame.size.width
} }
set(value) { set(value) {
layer.frame.size.width = value frame.size.width = value
if .None != shape { if .None != shape {
layer.frame.size.height = value frame.size.height = value
} }
} }
} }
...@@ -122,12 +134,12 @@ public class MaterialView : UIView { ...@@ -122,12 +134,12 @@ public class MaterialView : UIView {
*/ */
public var height: CGFloat { public var height: CGFloat {
get { get {
return layer.frame.size.height return frame.size.height
} }
set(value) { set(value) {
layer.frame.size.height = value frame.size.height = value
if .None != shape { if .None != shape {
layer.frame.size.width = value frame.size.width = value
} }
} }
} }
...@@ -178,18 +190,6 @@ public class MaterialView : UIView { ...@@ -178,18 +190,6 @@ public class MaterialView : UIView {
} }
/** /**
:name: masksToBounds
*/
public var masksToBounds: Bool {
get {
return visualLayer.masksToBounds
}
set(value) {
visualLayer.masksToBounds = value
}
}
/**
:name: cornerRadius :name: cornerRadius
*/ */
public var cornerRadius: MaterialRadius? { public var cornerRadius: MaterialRadius? {
...@@ -210,9 +210,9 @@ public class MaterialView : UIView { ...@@ -210,9 +210,9 @@ public class MaterialView : UIView {
didSet { didSet {
if .None != shape { if .None != shape {
if width < height { if width < height {
layer.frame.size.width = height frame.size.width = height
} else { } else {
layer.frame.size.height = width frame.size.height = width
} }
} }
} }
......
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