Commit b96584a0 by Daniel Dahan

fixed issue with Layout type in alignFromTop

parent e880bef7
......@@ -11,6 +11,8 @@
967513CC1C136BB7009F455A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967513CB1C136BB7009F455A /* ViewController.swift */; };
967513D11C136BB7009F455A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 967513D01C136BB7009F455A /* Assets.xcassets */; };
967513D41C136BB7009F455A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 967513D21C136BB7009F455A /* LaunchScreen.storyboard */; };
96B8C0AE1D04D0D90084F68A /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96B8C0AD1D04D0D90084F68A /* Material.framework */; };
96B8C0AF1D04D0D90084F68A /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96B8C0AD1D04D0D90084F68A /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -20,6 +22,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
96B8C0AF1D04D0D90084F68A /* Material.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -33,6 +36,7 @@
967513D01C136BB7009F455A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
967513D31C136BB7009F455A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
967513D51C136BB7009F455A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
96B8C0AD1D04D0D90084F68A /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-dciwtavdzrmtrifplxfnouazaqvx/Build/Products/Debug-iphonesimulator/Material.framework"; sourceTree = "<absolute>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -40,6 +44,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
96B8C0AE1D04D0D90084F68A /* Material.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -49,6 +54,7 @@
967513BD1C136BB7009F455A = {
isa = PBXGroup;
children = (
96B8C0AD1D04D0D90084F68A /* Material.framework */,
967513C81C136BB7009F455A /* CardView */,
967513C71C136BB7009F455A /* Products */,
);
......
......@@ -41,8 +41,8 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareAlignToParentHorizontallyAndVerticallyExample()
// prepareCenterExample()
// prepareAlignToParentHorizontallyAndVerticallyExample()
prepareCenterExample()
}
/// General preparation statements.
......
......@@ -256,9 +256,6 @@ public class CardView : MaterialPulseView {
public func reloadView() {
// clear constraints so new ones do not conflict
removeConstraints(constraints)
for v in subviews {
v.removeFromSuperview()
}
var verticalFormat: String = "V:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
......
......@@ -353,9 +353,6 @@ public class ImageCardView : MaterialPulseView {
public func reloadView() {
// clear constraints so new ones do not conflict
removeConstraints(constraints)
for v in subviews {
v.removeFromSuperview()
}
var verticalFormat: String = "V:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
......
......@@ -145,7 +145,7 @@ public extension Layout {
/// AlignFromTop
public func alignFromTop(child: UIView, top: CGFloat = 0) {
if let v: UIView = context {
Layout.alignFromTopLeft(v, child: child, top: top)
Layout.alignFromTop(v, child: child, top: top)
}
}
......@@ -196,13 +196,13 @@ public extension Layout {
public extension Layout {
/// Width
public class func width(parent: UIView, child: UIView, width: CGFloat = 0) {
prepareForConstraint(parent, children: [child])
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .Width, multiplier: 1, constant: width))
}
/// Height
public class func height(parent: UIView, child: UIView, height: CGFloat = 0) {
prepareForConstraint(parent, children: [child])
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1, constant: height))
}
......@@ -240,14 +240,14 @@ public extension Layout {
/// AlignToParentHorizontally
public class func alignToParentHorizontally(parent: UIView, child: UIView, left: CGFloat = 0, right: CGFloat = 0) {
prepareForConstraint(parent, children: [child])
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .Left, relatedBy: .Equal, toItem: parent, attribute: .Left, multiplier: 1, constant: left))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .Right, relatedBy: .Equal, toItem: parent, attribute: .Right, multiplier: 1, constant: -right))
}
/// AlignToParentVertically
public class func alignToParentVertically(parent: UIView, child: UIView, top: CGFloat = 0, bottom: CGFloat = 0) {
prepareForConstraint(parent, children: [child])
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .Top, relatedBy: .Equal, toItem: parent, attribute: .Top, multiplier: 1, constant: top))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .Bottom, relatedBy: .Equal, toItem: parent, attribute: .Bottom, multiplier: 1, constant: -bottom))
}
......@@ -284,25 +284,25 @@ public extension Layout {
/// AlignFromTop
public class func alignFromTop(parent: UIView, child: UIView, top: CGFloat = 0) {
prepareForConstraint(parent, children: [child])
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .Top, relatedBy: .Equal, toItem: parent, attribute: .Top, multiplier: 1, constant: top))
}
/// AlignFromLeft
public class func alignFromLeft(parent: UIView, child: UIView, left: CGFloat = 0) {
prepareForConstraint(parent, children: [child])
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .Left, relatedBy: .Equal, toItem: parent, attribute: .Left, multiplier: 1, constant: left))
}
/// AlignFromBottom
public class func alignFromBottom(parent: UIView, child: UIView, bottom: CGFloat = 0) {
prepareForConstraint(parent, children: [child])
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .Bottom, relatedBy: .Equal, toItem: parent, attribute: .Bottom, multiplier: 1, constant: -bottom))
}
/// AlignFromRight
public class func alignFromRight(parent: UIView, child: UIView, right: CGFloat = 0) {
prepareForConstraint(parent, children: [child])
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .Right, relatedBy: .Equal, toItem: parent, attribute: .Right, multiplier: 1, constant: -right))
}
......@@ -314,13 +314,13 @@ public extension Layout {
/// CenterHorizontally
public class func centerHorizontally(parent: UIView, child: UIView, constant: CGFloat = 0) {
prepareForConstraint(parent, children: [child])
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .CenterX, relatedBy: .Equal, toItem: parent, attribute: .CenterX, multiplier: 1, constant: constant))
}
/// CenterVertically
public class func centerVertically(parent: UIView, child: UIView, constant: CGFloat = 0) {
prepareForConstraint(parent, children: [child])
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .CenterY, relatedBy: .Equal, toItem: parent, attribute: .CenterY, multiplier: 1, constant: constant))
}
......@@ -340,12 +340,17 @@ public extension Layout {
}
/// prepareForConstraint
private class func prepareForConstraint(parent: UIView, child: UIView) {
if parent != child.superview {
parent.addSubview(child)
}
child.translatesAutoresizingMaskIntoConstraints = false
}
/// prepareForConstraint
private class func prepareForConstraint(parent: UIView, children: [UIView]) {
for v in children {
if parent != v.superview {
parent.addSubview(v)
}
v.translatesAutoresizingMaskIntoConstraints = false
prepareForConstraint(parent, child: v)
}
}
}
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