Commit a6dd917a by Daniel Dahan

updated MaterialLayout internals

parent 2adcab8e
Pod::Spec.new do |s|
s.name = 'MK'
s.version = '1.17.1'
s.version = '1.17.2'
s.license = { :type => "AGPLv3+", :file => "LICENSE" }
s.summary = 'A Material Design Framework In Swift'
s.homepage = 'http://materialkit.io'
......
......@@ -24,9 +24,6 @@ public class FabButton : MaterialButton {
*/
public override func layoutSubviews() {
super.layoutSubviews()
if false == translatesAutoresizingMaskIntoConstraints {
prepareShape()
}
}
//
......
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.17.1</string>
<string>1.17.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -100,7 +100,6 @@ public class MaterialButton : UIButton {
frame.size.width = value
if nil != shape {
frame.size.height = value
prepareShape()
}
}
}
......@@ -116,7 +115,6 @@ public class MaterialButton : UIButton {
frame.size.height = value
if nil != shape {
frame.size.width = value
prepareShape()
}
}
}
......@@ -172,7 +170,9 @@ public class MaterialButton : UIButton {
public var cornerRadius: MaterialRadius! {
didSet {
layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .None : cornerRadius!)
shape = nil
if .Circle == shape {
shape = nil
}
}
}
......@@ -187,7 +187,6 @@ public class MaterialButton : UIButton {
} else {
frame.size.height = width
}
prepareShape()
}
}
}
......@@ -274,6 +273,8 @@ public class MaterialButton : UIButton {
*/
public override func layoutSubviews() {
super.layoutSubviews()
prepareShape()
visualLayer.frame = bounds
visualLayer.cornerRadius = layer.cornerRadius
......@@ -291,7 +292,7 @@ public class MaterialButton : UIButton {
// set start position
CATransaction.begin()
CATransaction.setAnimationDuration(0)
let w: CGFloat = width / 2
let w: CGFloat = (width < height ? height : width) / 2
pulseLayer.hidden = false
pulseLayer.position = point
pulseLayer.bounds = CGRectMake(0, 0, w, w)
......@@ -351,7 +352,9 @@ public class MaterialButton : UIButton {
// :name: prepareShape
//
internal func prepareShape() {
layer.cornerRadius = .Square == shape ? 0 : width / 2
if .Circle == shape {
layer.cornerRadius = width / 2
}
}
//
......
......@@ -86,49 +86,40 @@ public struct MaterialLayout {
:name: alignToParentWithInsets
*/
public static func alignToParentWithInsets(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) {
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint("H:|-(left)-[child]-(right)-|", options: [], metrics: ["left": left, "right": right], views: views))
parent.addConstraints(constraint("V:|-(top)-[child]-(bottom)-|", options: [], metrics: ["bottom": bottom, "top": top], views: views))
alignToParentHorizontallyWithInsets(parent, child: child, left: left, right: right)
alignToParentVerticallyWithInsets(parent, child: child, top: top, bottom: bottom)
}
/**
:name: alignFromTopLeft
*/
public static func alignFromTopLeft(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0) {
let metrics: Dictionary<String, AnyObject> = ["top" : top, "left" : left]
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint("H:|-(left)-[child]", options: [], metrics: metrics, views: views))
parent.addConstraints(constraint("V:|-(top)-[child]", options: [], metrics: metrics, views: views))
alignFromTop(parent, child: child, top: top)
alignFromLeft(parent, child: child, left: left)
}
/**
:name: alignFromTopRight
*/
public static func alignFromTopRight(parent: UIView, child: UIView, top: CGFloat = 0, right: CGFloat = 0) {
let metrics: Dictionary<String, AnyObject> = ["top" : top, "right" : right]
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint("H:[child]-(right)-|", options: [], metrics: metrics, views: views))
parent.addConstraints(constraint("V:|-(top)-[child]", options: [], metrics: metrics, views: views))
alignFromTop(parent, child: child, top: top)
alignFromRight(parent, child: child, right: right)
}
/**
:name: alignFromBottomLeft
*/
public static func alignFromBottomLeft(parent: UIView, child: UIView, bottom: CGFloat = 0, left: CGFloat = 0) {
let metrics: Dictionary<String, AnyObject> = ["bottom" : bottom, "left" : left]
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint("H:|-(left)-[child]", options: [], metrics: metrics, views: views))
parent.addConstraints(constraint("V:[child]-(bottom)-|", options: [], metrics: metrics, views: views))
alignFromBottom(parent, child: child, bottom: bottom)
alignFromLeft(parent, child: child, left: left)
}
/**
:name: alignFromBottomRight
*/
public static func alignFromBottomRight(parent: UIView, child: UIView, bottom: CGFloat = 0, right: CGFloat = 0) {
let metrics: Dictionary<String, AnyObject> = ["bottom" : bottom, "right" : right]
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint("H:[child]-(right)-|", options: [], metrics: metrics, views: views))
parent.addConstraints(constraint("V:[child]-(bottom)-|", options: [], metrics: metrics, views: views))
alignFromBottom(parent, child: child, bottom: bottom)
alignFromRight(parent, child: child, right: right)
}
/**
......
......@@ -75,7 +75,7 @@ public class MaterialPulseView: MaterialView {
// set start position
CATransaction.begin()
CATransaction.setAnimationDuration(0)
let w: CGFloat = width / 2
let w: CGFloat = (width < height ? height : width) / 2
pulseLayer.hidden = false
pulseLayer.position = point
pulseLayer.bounds = CGRectMake(0, 0, w, w)
......
......@@ -116,7 +116,6 @@ public class MaterialView: UIView {
frame.size.width = value
if nil != shape {
frame.size.height = value
prepareShape()
}
}
}
......@@ -132,7 +131,6 @@ public class MaterialView: UIView {
frame.size.height = value
if nil != shape {
frame.size.width = value
prepareShape()
}
}
}
......@@ -188,7 +186,9 @@ public class MaterialView: UIView {
public var cornerRadius: MaterialRadius! {
didSet {
layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .None : cornerRadius!)
shape = nil
if .Circle == shape {
shape = nil
}
}
}
......@@ -203,7 +203,6 @@ public class MaterialView: UIView {
} else {
frame.size.height = width
}
prepareShape()
}
}
}
......@@ -281,6 +280,8 @@ public class MaterialView: UIView {
*/
public override func layoutSubviews() {
super.layoutSubviews()
prepareShape()
visualLayer.frame = bounds
visualLayer.cornerRadius = layer.cornerRadius
}
......@@ -313,7 +314,9 @@ public class MaterialView: UIView {
// :name: prepareShape
//
internal func prepareShape() {
layer.cornerRadius = .Square == shape ? 0 : width / 2
if .Circle == shape {
layer.cornerRadius = width / 2
}
}
}
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