Commit 6afa56be by Daniel Dahan

updated all projects to use Layout

parent eb4851dc
...@@ -90,19 +90,17 @@ class AppLeftViewController: UIViewController { ...@@ -90,19 +90,17 @@ class AppLeftViewController: UIViewController {
profileView.shape = .Circle profileView.shape = .Circle
profileView.borderColor = MaterialColor.white profileView.borderColor = MaterialColor.white
profileView.borderWidth = 3 profileView.borderWidth = 3
view.addSubview(profileView)
let nameLabel: UILabel = UILabel() let nameLabel: UILabel = UILabel()
nameLabel.text = "Michael Smith" nameLabel.text = "Michael Smith"
nameLabel.textColor = MaterialColor.white nameLabel.textColor = MaterialColor.white
nameLabel.font = RobotoFont.mediumWithSize(18) nameLabel.font = RobotoFont.mediumWithSize(18)
view.addSubview(nameLabel)
Layout.alignFromTopLeft(view, child: profileView, top: 30, left: (view.bounds.width - 72) / 2) view.layout.size(profileView, width: 72, height: 72)
Layout.size(view, child: profileView, width: 72, height: 72) view.layout.alignFromTopLeft(profileView, top: 30, left: (view.bounds.width - 72) / 2)
Layout.alignFromTop(view, child: nameLabel, top: 130) view.layout.alignFromTop(nameLabel, top: 130)
Layout.alignToParentHorizontally(view, child: nameLabel, left: 20, right: 20) view.layout.horizontally(nameLabel, left: 20, right: 20)
} }
/// Prepares the tableView. /// Prepares the tableView.
...@@ -114,8 +112,7 @@ class AppLeftViewController: UIViewController { ...@@ -114,8 +112,7 @@ class AppLeftViewController: UIViewController {
tableView.separatorStyle = .None tableView.separatorStyle = .None
// Use Layout to easily align the tableView. // Use Layout to easily align the tableView.
view.addSubview(tableView) view.layout.align(tableView, top: 170)
Layout.alignToParent(view, child: tableView, top: 170)
} }
} }
......
...@@ -140,9 +140,8 @@ class AppMenuController: MenuController { ...@@ -140,9 +140,8 @@ class AppMenuController: MenuController {
menuView.menu.views = [menuButton, blueButton, greenButton, yellowButton] menuView.menu.views = [menuButton, blueButton, greenButton, yellowButton]
menuView.delegate = self menuView.delegate = self
view.addSubview(menuView) view.layout.size(menuView, width: baseSize.width, height: baseSize.height)
Layout.size(view, child: menuView, width: baseSize.width, height: baseSize.height) view.layout.alignFromBottomRight(menuView, bottom: menuViewInset, right: menuViewInset)
Layout.alignFromBottomRight(view, child: menuView, bottom: menuViewInset, right: menuViewInset)
} }
/// Prepare tabBarItem. /// Prepare tabBarItem.
......
...@@ -32,31 +32,11 @@ import UIKit ...@@ -32,31 +32,11 @@ import UIKit
import Material import Material
class AppNavigationController: NavigationController { class AppNavigationController: NavigationController {
/// StatusBar color reference.
// private var statusBarView: MaterialView?
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
// prepareStatusBarView()
prepareNavigationBar() prepareNavigationBar()
} }
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
// statusBarView?.hidden = MaterialDevice.statusBarHidden
}
/// Prepares the statusBarView
// private func prepareStatusBarView() {
// statusBarView = MaterialView()
// statusBarView!.backgroundColor = MaterialColor.blue.darken2
//
// view.addSubview(statusBarView!)
// Layout.alignFromTop(view, child: statusBarView!)
// Layout.alignToParentHorizontally(view, child: statusBarView!)
// Layout.height(view, child: statusBarView!, height: 20)
// }
/// Prepares the navigationBar /// Prepares the navigationBar
private func prepareNavigationBar() { private func prepareNavigationBar() {
navigationBar.tintColor = MaterialColor.white navigationBar.tintColor = MaterialColor.white
......
...@@ -95,7 +95,7 @@ class ItemViewController: UIViewController { ...@@ -95,7 +95,7 @@ class ItemViewController: UIViewController {
scrollView.frame = view.bounds scrollView.frame = view.bounds
scrollView.removeConstraints(scrollView.constraints) scrollView.removeConstraints(scrollView.constraints)
Layout.width(scrollView, child: imageCardView, width: scrollView.bounds.width) scrollView.layout.width(imageCardView, width: scrollView.bounds.width)
imageCardView.layoutIfNeeded() imageCardView.layoutIfNeeded()
scrollView.contentSize = CGSizeMake(view.bounds.width, imageCardView.height) scrollView.contentSize = CGSizeMake(view.bounds.width, imageCardView.height)
...@@ -167,9 +167,6 @@ class ItemViewController: UIViewController { ...@@ -167,9 +167,6 @@ class ItemViewController: UIViewController {
let image: UIImage? = UIImage(named: data["image"] as! String) let image: UIImage? = UIImage(named: data["image"] as! String)
imageCardView.image = image imageCardView.image = image
scrollView.addSubview(imageCardView)
imageCardView.translatesAutoresizingMaskIntoConstraints = false
} }
} }
} }
...@@ -261,8 +261,7 @@ class RecipesViewController: UIViewController { ...@@ -261,8 +261,7 @@ class RecipesViewController: UIViewController {
tableView.delegate = self tableView.delegate = self
// Use Layout to easily align the tableView. // Use Layout to easily align the tableView.
view.addSubview(tableView) view.layout.align(tableView)
Layout.alignToParent(view, child: tableView)
} }
} }
...@@ -307,8 +306,7 @@ extension RecipesViewController: UITableViewDataSource { ...@@ -307,8 +306,7 @@ extension RecipesViewController: UITableViewDataSource {
label.textColor = MaterialColor.grey.darken1 label.textColor = MaterialColor.grey.darken1
label.text = "Favorites" label.text = "Favorites"
header.addSubview(label) header.layout.align(label, left: 24)
Layout.alignToParent(header, child: label, left: 24)
return header return header
} }
......
...@@ -70,8 +70,7 @@ class RecommendationViewController: UIViewController { ...@@ -70,8 +70,7 @@ class RecommendationViewController: UIViewController {
tableView.delegate = self tableView.delegate = self
// Use Layout to easily align the tableView. // Use Layout to easily align the tableView.
view.addSubview(tableView) view.layout.align(tableView)
Layout.alignToParent(view, child: tableView)
} }
} }
...@@ -116,8 +115,7 @@ extension RecommendationViewController: UITableViewDataSource { ...@@ -116,8 +115,7 @@ extension RecommendationViewController: UITableViewDataSource {
label.textColor = MaterialColor.grey.darken1 label.textColor = MaterialColor.grey.darken1
label.text = "Recommendations" label.text = "Recommendations"
header.addSubview(label) header.layout.align(label, left: 24)
Layout.alignToParent(header, child: label, left: 24)
return header return header
} }
......
...@@ -226,7 +226,7 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg ...@@ -226,7 +226,7 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
captureView.tapToExposeEnabled = true captureView.tapToExposeEnabled = true
captureView.delegate = self captureView.delegate = self
captureView.captureSession.delegate = self captureView.captureSession.delegate = self
Layout.alignToParent(view, child: captureView) view.layout.align(captureView)
} }
/** /**
......
...@@ -79,9 +79,8 @@ class ViewController: UIViewController { ...@@ -79,9 +79,8 @@ class ViewController: UIViewController {
cardView.leftButtons = [btn1, btn2] cardView.leftButtons = [btn1, btn2]
// To support orientation changes, use Layout. // To support orientation changes, use Layout.
view.addSubview(cardView) view.layout.alignFromTop(cardView, top: 100)
Layout.alignFromTop(view, child: cardView, top: 100) view.layout.horizontally(cardView, left: 20, right: 20)
Layout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
} }
private func prepareCardViewWithoutPulseBackgroundImageExample() { private func prepareCardViewWithoutPulseBackgroundImageExample() {
...@@ -118,9 +117,8 @@ class ViewController: UIViewController { ...@@ -118,9 +117,8 @@ class ViewController: UIViewController {
cardView.leftButtons = [btn1] cardView.leftButtons = [btn1]
// To support orientation changes, use Layout. // To support orientation changes, use Layout.
view.addSubview(cardView) view.layout.alignFromTop(cardView, top: 100)
Layout.alignFromTop(view, child: cardView, top: 100) view.layout.horizontally(cardView, left: 20, right: 20)
Layout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
} }
private func prepareCardViewWithPulseBackgroundImageExample() { private func prepareCardViewWithPulseBackgroundImageExample() {
...@@ -158,9 +156,8 @@ class ViewController: UIViewController { ...@@ -158,9 +156,8 @@ class ViewController: UIViewController {
cardView.leftButtons = [btn1] cardView.leftButtons = [btn1]
// To support orientation changes, use Layout. // To support orientation changes, use Layout.
view.addSubview(cardView) view.layout.alignFromTop(cardView, top: 100)
Layout.alignFromTop(view, child: cardView, top: 100) view.layout.horizontally(cardView, left: 20, right: 20)
Layout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
} }
private func prepareCardViewButtonBarExample() { private func prepareCardViewButtonBarExample() {
...@@ -197,9 +194,8 @@ class ViewController: UIViewController { ...@@ -197,9 +194,8 @@ class ViewController: UIViewController {
cardView.rightButtons = [btn2, btn3] cardView.rightButtons = [btn2, btn3]
// To support orientation changes, use Layout. // To support orientation changes, use Layout.
view.addSubview(cardView) view.layout.alignFromTop(cardView, top: 100)
Layout.alignFromTop(view, child: cardView, top: 100) view.layout.horizontally(cardView, left: 20, right: 20)
Layout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
} }
} }
...@@ -83,9 +83,8 @@ class ViewController: UIViewController { ...@@ -83,9 +83,8 @@ class ViewController: UIViewController {
imageCardView.leftButtons = [btn1, btn2] imageCardView.leftButtons = [btn1, btn2]
// To support orientation changes, use Layout. // To support orientation changes, use Layout.
view.addSubview(imageCardView) view.layout.alignFromTop(imageCardView, top: 100)
Layout.alignFromTop(view, child: imageCardView, top: 100) view.layout.horizontally(imageCardView, left: 20, right: 20)
Layout.alignToParentHorizontally(view, child: imageCardView, left: 20, right: 20)
} }
private func prepareImageCardViewWithoutDetailLabelAndDividerExample() { private func prepareImageCardViewWithoutDetailLabelAndDividerExample() {
...@@ -133,9 +132,8 @@ class ViewController: UIViewController { ...@@ -133,9 +132,8 @@ class ViewController: UIViewController {
imageCardView.rightButtons = [btn1, btn2, btn3] imageCardView.rightButtons = [btn1, btn2, btn3]
// To support orientation changes, use Layout. // To support orientation changes, use Layout.
view.addSubview(imageCardView) view.layout.alignFromTop(imageCardView, top: 100)
Layout.alignFromTop(view, child: imageCardView, top: 100) view.layout.horizontally(imageCardView, left: 20, right: 20)
Layout.alignToParentHorizontally(view, child: imageCardView, left: 20, right: 20)
} }
} }
...@@ -85,8 +85,7 @@ class ViewController: UIViewController { ...@@ -85,8 +85,7 @@ class ViewController: UIViewController {
collectionView.contentInset.top = 100 collectionView.contentInset.top = 100
collectionView.spacing = 16 collectionView.spacing = 16
view.addSubview(collectionView) view.layout.align(collectionView)
Layout.alignToParent(view, child: collectionView)
} }
} }
......
...@@ -47,35 +47,30 @@ class ViewController: UIViewController { ...@@ -47,35 +47,30 @@ class ViewController: UIViewController {
private func prepareMaterialDepth() { private func prepareMaterialDepth() {
let v1: MaterialView = MaterialView() let v1: MaterialView = MaterialView()
v1.depth = .Depth1 v1.depth = .Depth1
view.addSubview(v1)
let v2: MaterialView = MaterialView() let v2: MaterialView = MaterialView()
v2.depth = .Depth2 v2.depth = .Depth2
view.addSubview(v2)
let v3: MaterialView = MaterialView() let v3: MaterialView = MaterialView()
v3.depth = .Depth3 v3.depth = .Depth3
view.addSubview(v3)
let v4: MaterialView = MaterialView() let v4: MaterialView = MaterialView()
v4.depth = .Depth4 v4.depth = .Depth4
view.addSubview(v4)
let v5: MaterialView = MaterialView() let v5: MaterialView = MaterialView()
v5.depth = .Depth5 v5.depth = .Depth5
view.addSubview(v5)
let children: Array<UIView> = [v1, v2, v3, v4, v5] let children: Array<UIView> = [v1, v2, v3, v4, v5]
// Align the vs vertically with an equal height. // Align the vs vertically with an equal height.
Layout.alignToParentVertically(view, children: children, top: 100, bottom: 100, spacing: 20) view.layout.vertically(children, top: 100, bottom: 100, spacing: 20)
/* /*
Individually set the vs' horizontal alignment. Individually set the vs' horizontal alignment.
If this is left out, the intrinsic value is used for the view. If this is left out, the intrinsic value is used for the view.
*/ */
for v in children { for v in children {
Layout.alignToParentHorizontally(view, child: v, left: 20, right: 20) view.layout.horizontally(v, left: 20, right: 20)
} }
} }
} }
......
...@@ -113,9 +113,7 @@ class ViewController: UIViewController { ...@@ -113,9 +113,7 @@ class ViewController: UIViewController {
tableView.dataSource = self tableView.dataSource = self
tableView.delegate = self tableView.delegate = self
view.addSubview(tableView) view.layout.align(tableView, top: 20)
Layout.alignToParent(view, child: tableView, top: 20, left: 0, bottom: 0, right: 0)
} }
private func image(iconName:String!) -> UIImage? { private func image(iconName:String!) -> UIImage? {
......
...@@ -50,56 +50,47 @@ class ViewController: UIViewController, MaterialSwitchDelegate { ...@@ -50,56 +50,47 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
private func prepareView() { private func prepareView() {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
view.addSubview(topView)
view.addSubview(bottomView)
bottomView.backgroundColor = MaterialColor.grey.darken4 bottomView.backgroundColor = MaterialColor.grey.darken4
Layout.alignToParentHorizontally(view, child: topView) view.layout.horizontally(topView)
Layout.alignToParentHorizontally(view, child: bottomView) view.layout.horizontally(bottomView)
Layout.alignToParentVertically(view, children: [topView, bottomView]) view.layout.vertically([topView, bottomView])
} }
/// Prepares the LightContent MaterialSwitch. /// Prepares the LightContent MaterialSwitch.
private func prepareLightContentMaterialSwitch() { private func prepareLightContentMaterialSwitch() {
let c1: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small) let c1: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small)
c1.delegate = self c1.delegate = self
topView.addSubview(c1)
let c2: MaterialSwitch = MaterialSwitch(state: .On, style: .LightContent) let c2: MaterialSwitch = MaterialSwitch(state: .On, style: .LightContent)
c2.delegate = self c2.delegate = self
topView.addSubview(c2)
let c3: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Large) let c3: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Large)
c3.delegate = self c3.delegate = self
c3.enabled = false c3.enabled = false
topView.addSubview(c3)
Layout.alignToParentHorizontally(topView, child: c1) topView.layout.horizontally(c1)
Layout.alignToParentHorizontally(topView, child: c2) topView.layout.horizontally(c2)
Layout.alignToParentHorizontally(topView, child: c3) topView.layout.horizontally(c3)
Layout.alignToParentVertically(topView, children: [c1, c2, c3]) topView.layout.vertically([c1, c2, c3])
} }
/// Prepares the LightContent MaterialSwitch. /// Prepares the LightContent MaterialSwitch.
private func prepareDefaultMaterialSwitch() { private func prepareDefaultMaterialSwitch() {
let c1: MaterialSwitch = MaterialSwitch(state: .Off, style: .Default, size: .Small) let c1: MaterialSwitch = MaterialSwitch(state: .Off, style: .Default, size: .Small)
c1.delegate = self c1.delegate = self
bottomView.addSubview(c1)
let c2: MaterialSwitch = MaterialSwitch(state: .On) let c2: MaterialSwitch = MaterialSwitch(state: .On)
c2.delegate = self c2.delegate = self
bottomView.addSubview(c2)
let c3: MaterialSwitch = MaterialSwitch(state: .Off, style: .Default, size: .Large) let c3: MaterialSwitch = MaterialSwitch(state: .Off, style: .Default, size: .Large)
c3.delegate = self c3.delegate = self
c3.enabled = false c3.enabled = false
bottomView.addSubview(c3)
Layout.alignToParentHorizontally(bottomView, child: c1) bottomView.layout.horizontally(c1)
Layout.alignToParentHorizontally(bottomView, child: c2) bottomView.layout.horizontally(c2)
Layout.alignToParentHorizontally(bottomView, child: c3) bottomView.layout.horizontally(c3)
Layout.alignToParentVertically(bottomView, children: [c1, c2, c3]) bottomView.layout.vertically([c1, c2, c3])
} }
internal func materialSwitchStateChanged(control: MaterialSwitch) { internal func materialSwitchStateChanged(control: MaterialSwitch) {
......
...@@ -148,9 +148,8 @@ class AppMenuController: MenuController { ...@@ -148,9 +148,8 @@ class AppMenuController: MenuController {
menuView.menu.views = [menuButton, blueButton, greenButton, yellowButton] menuView.menu.views = [menuButton, blueButton, greenButton, yellowButton]
menuView.delegate = self menuView.delegate = self
view.addSubview(menuView) view.layout.size(menuView, width: baseSize.width, height: baseSize.height)
Layout.size(view, child: menuView, width: baseSize.width, height: baseSize.height) view.layout.alignFromBottomRight(menuView, bottom: menuViewInset, right: menuViewInset)
Layout.alignFromBottomRight(view, child: menuView, bottom: menuViewInset, right: menuViewInset)
} }
} }
......
...@@ -137,9 +137,8 @@ class ViewController: UIViewController { ...@@ -137,9 +137,8 @@ class ViewController: UIViewController {
menuView.menu.baseSize = CGSizeMake(diameter, diameter) menuView.menu.baseSize = CGSizeMake(diameter, diameter)
menuView.menu.views = [btn1, btn2, btn3, btn4] menuView.menu.views = [btn1, btn2, btn3, btn4]
view.addSubview(menuView) view.layout.size(menuView, width: diameter, height: diameter)
Layout.size(view, child: menuView, width: diameter, height: diameter) view.layout.alignFromBottomLeft(menuView, bottom: 16, left: (view.bounds.width - diameter) / 2)
Layout.alignFromBottomLeft(view, child: menuView, bottom: 16, left: (view.bounds.width - diameter) / 2)
} }
} }
...@@ -59,9 +59,7 @@ class ViewController: UIViewController { ...@@ -59,9 +59,7 @@ class ViewController: UIViewController {
/// Prepares the containerView. /// Prepares the containerView.
private func prepareContainerView() { private func prepareContainerView() {
containerView = UIView() containerView = UIView()
view.addSubview(containerView) view.layout.align(containerView, top: 100, left: 20, right: 20)
Layout.alignToParent(view, child: containerView, top: 100, left: 20, right: 20)
} }
/// Prepares the toolbar /// Prepares the toolbar
......
...@@ -75,8 +75,7 @@ class AppLeftViewController: UIViewController { ...@@ -75,8 +75,7 @@ class AppLeftViewController: UIViewController {
tableView.separatorStyle = .None tableView.separatorStyle = .None
// Use Layout to easily align the tableView. // Use Layout to easily align the tableView.
view.addSubview(tableView) view.layout.align(tableView)
Layout.alignToParent(view, child: tableView)
} }
} }
......
...@@ -117,8 +117,7 @@ class ViewController: UIViewController { ...@@ -117,8 +117,7 @@ class ViewController: UIViewController {
cardView.leftButtons = [closeButton] cardView.leftButtons = [closeButton]
cardView.rightButtons = [settingButton] cardView.rightButtons = [settingButton]
view.addSubview(cardView) view.layout.align(cardView, left: 10, right: 10, top: 100, bottom: 100)
Layout.alignToParent(view, child: cardView, left: 10, right: 10, top: 100, bottom: 100)
} }
} }
......
...@@ -69,10 +69,9 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -69,10 +69,9 @@ class ViewController: UIViewController, TextFieldDelegate {
btn.setTitle("Resign", forState: .Normal) btn.setTitle("Resign", forState: .Normal)
btn.setTitleColor(MaterialColor.blue.base, forState: .Normal) btn.setTitleColor(MaterialColor.blue.base, forState: .Normal)
btn.setTitleColor(MaterialColor.blue.base, forState: .Highlighted) btn.setTitleColor(MaterialColor.blue.base, forState: .Highlighted)
view.addSubview(btn)
Layout.alignFromBottomRight(view, child: btn, bottom: 24, right: 24) view.layout.size(btn, width: 100, height: 50)
Layout.size(view, child: btn, width: 100, height: 50) view.layout.alignFromBottomRight(btn, bottom: 24, right: 24)
} }
/// Handle the resign responder button. /// Handle the resign responder button.
...@@ -92,12 +91,10 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -92,12 +91,10 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField.textAlignment = .Center nameField.textAlignment = .Center
nameField.clearButtonMode = .WhileEditing nameField.clearButtonMode = .WhileEditing
view.addSubview(nameField)
// Size the TextField to the maximum width, less 40 pixels on either side // Size the TextField to the maximum width, less 40 pixels on either side
// with a top margin of 40 pixels. // with a top margin of 40 pixels.
Layout.alignFromTop(view, child: nameField, top: 40) view.layout.alignFromTop(nameField, top: 40)
Layout.alignToParentHorizontally(view, child: nameField, left: 40, right: 40) view.layout.horizontally(nameField, left: 40, right: 40)
} }
/// Prepares the email TextField. /// Prepares the email TextField.
...@@ -126,12 +123,10 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -126,12 +123,10 @@ class ViewController: UIViewController, TextFieldDelegate {
// Setting the visibilityFlatButton color. // Setting the visibilityFlatButton color.
passwordField.visibilityIconButton?.tintColor = MaterialColor.green.base.colorWithAlphaComponent(passwordField.secureTextEntry ? 0.38 : 0.54) passwordField.visibilityIconButton?.tintColor = MaterialColor.green.base.colorWithAlphaComponent(passwordField.secureTextEntry ? 0.38 : 0.54)
view.addSubview(passwordField)
// Size the TextField to the maximum width, less 40 pixels on either side // Size the TextField to the maximum width, less 40 pixels on either side
// with a top margin of 200 pixels. // with a top margin of 200 pixels.
Layout.alignFromTop(view, child: passwordField, top: 200) view.layout.alignFromTop(passwordField, top: 200)
Layout.alignToParentHorizontally(view, child: passwordField, left: 40, right: 40) view.layout.horizontally(passwordField, left: 40, right: 40)
} }
/// Executed when the 'return' key is pressed when using the emailField. /// Executed when the 'return' key is pressed when using the emailField.
......
...@@ -75,8 +75,7 @@ class ViewController: UIViewController, TextDelegate { ...@@ -75,8 +75,7 @@ class ViewController: UIViewController, TextDelegate {
textView.titleLabelColor = MaterialColor.grey.base textView.titleLabelColor = MaterialColor.grey.base
textView.titleLabelActiveColor = MaterialColor.blue.accent3 textView.titleLabelActiveColor = MaterialColor.blue.accent3
view.addSubview(textView) view.layout.align(textView!, top: 124, left: 24, bottom: 24, right: 24)
Layout.alignToParent(view, child: textView!, top: 124, left: 24, bottom: 24, right: 24)
} }
/** /**
......
...@@ -59,9 +59,7 @@ class ViewController: UIViewController { ...@@ -59,9 +59,7 @@ class ViewController: UIViewController {
/// Prepares the containerView. /// Prepares the containerView.
private func prepareContainerView() { private func prepareContainerView() {
containerView = UIView() containerView = UIView()
view.addSubview(containerView) view.layout.align(containerView, top: 100, left: 20, right: 20)
Layout.alignToParent(view, child: containerView, top: 100, left: 20, right: 20)
} }
/// Prepares the toolbar /// Prepares the toolbar
......
...@@ -43,9 +43,8 @@ class RootViewController: UIViewController { ...@@ -43,9 +43,8 @@ class RootViewController: UIViewController {
fabButton.setImage(img, forState: .Highlighted) fabButton.setImage(img, forState: .Highlighted)
fabButton.addTarget(self, action: #selector(handleFabButton), forControlEvents: .TouchUpInside) fabButton.addTarget(self, action: #selector(handleFabButton), forControlEvents: .TouchUpInside)
view.addSubview(fabButton) view.layout.size(fabButton, width: 64, height: 64)
Layout.alignFromBottomRight(view, child: fabButton, bottom: 16, right: 16) view.layout.alignFromBottomRight(fabButton, bottom: 16, right: 16)
Layout.size(view, child: fabButton, width: 64, height: 64)
} }
// FabButton handler. // FabButton handler.
......
...@@ -233,8 +233,8 @@ public class BottomTabBar : UITabBar { ...@@ -233,8 +233,8 @@ public class BottomTabBar : UITabBar {
super.didMoveToSuperview() super.didMoveToSuperview()
if autoLayoutToSuperview { if autoLayoutToSuperview {
if let v: UIView = superview { if let v: UIView = superview {
Layout.alignFromBottom(v, child: self) v.layout.alignFromBottom(self)
Layout.alignToParentHorizontally(v, child: self) v.layout.horizontally(self)
} }
} }
} }
......
...@@ -274,18 +274,14 @@ public class CardView : MaterialPulseView { ...@@ -274,18 +274,14 @@ public class CardView : MaterialPulseView {
// title // title
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
addSubview(v)
verticalFormat += "-[titleLabel]" verticalFormat += "-[titleLabel]"
views["titleLabel"] = v views["titleLabel"] = v
Layout.alignToParentHorizontally(self, child: v, left: contentInset.left + titleLabelInset.left, right: contentInset.right + titleLabelInset.right) layout.horizontally(v, left: contentInset.left + titleLabelInset.left, right: contentInset.right + titleLabelInset.right)
} }
// detail // detail
if let v: UIView = contentView { if let v: UIView = contentView {
addSubview(v)
if nil == titleLabel { if nil == titleLabel {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentViewInset.top metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentViewInset.top
} else { } else {
...@@ -296,7 +292,7 @@ public class CardView : MaterialPulseView { ...@@ -296,7 +292,7 @@ public class CardView : MaterialPulseView {
verticalFormat += "-[contentView]" verticalFormat += "-[contentView]"
views["contentView"] = v views["contentView"] = v
Layout.alignToParentHorizontally(self, child: v, left: contentInset.left + contentViewInset.left, right: contentInset.right + contentViewInset.right) layout.horizontally(v, left: contentInset.left + contentViewInset.left, right: contentInset.right + contentViewInset.right)
} }
// leftButtons // leftButtons
...@@ -318,8 +314,7 @@ public class CardView : MaterialPulseView { ...@@ -318,8 +314,7 @@ public class CardView : MaterialPulseView {
h += "[\(k)]" h += "[\(k)]"
addSubview(b) layout.alignFromBottom(b, bottom: contentInset.bottom + leftButtonsInset.bottom)
Layout.alignFromBottom(self, child: b, bottom: contentInset.bottom + leftButtonsInset.bottom)
i += 1 i += 1
} }
...@@ -348,8 +343,7 @@ public class CardView : MaterialPulseView { ...@@ -348,8 +343,7 @@ public class CardView : MaterialPulseView {
h += "-(right_left)-" h += "-(right_left)-"
} }
addSubview(b) layout.alignFromBottom(b, bottom: contentInset.bottom + rightButtonsInset.bottom)
Layout.alignFromBottom(self, child: b, bottom: contentInset.bottom + rightButtonsInset.bottom)
i -= 1 i -= 1
} }
......
...@@ -374,21 +374,17 @@ public class ImageCardView : MaterialPulseView { ...@@ -374,21 +374,17 @@ public class ImageCardView : MaterialPulseView {
// title // title
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
addSubview(v)
if nil == imageLayer?.contents { if nil == imageLayer?.contents {
verticalFormat += "-[titleLabel]" verticalFormat += "-[titleLabel]"
views["titleLabel"] = v views["titleLabel"] = v
} else { } else {
Layout.alignFromTop(self, child: v, top: contentInset.top + titleLabelInset.top) layout.alignFromTop(v, top: contentInset.top + titleLabelInset.top)
} }
Layout.alignToParentHorizontally(self, child: v, left: contentInset.left + titleLabelInset.left, right: contentInset.right + titleLabelInset.right) layout.horizontally(v, left: contentInset.left + titleLabelInset.left, right: contentInset.right + titleLabelInset.right)
} }
// detail // detail
if let v: UIView = contentView { if let v: UIView = contentView {
addSubview(v)
if nil == imageLayer?.contents && nil != titleLabel { if nil == imageLayer?.contents && nil != titleLabel {
verticalFormat += "-(insetB)" verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInset.bottom + contentViewInset.top metrics["insetB"] = titleLabelInset.bottom + contentViewInset.top
...@@ -399,7 +395,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -399,7 +395,7 @@ public class ImageCardView : MaterialPulseView {
verticalFormat += "-[contentView]" verticalFormat += "-[contentView]"
views["contentView"] = v views["contentView"] = v
Layout.alignToParentHorizontally(self, child: v, left: contentInset.left + contentViewInset.left, right: contentInset.right + contentViewInset.right) layout.horizontally(v, left: contentInset.left + contentViewInset.left, right: contentInset.right + contentViewInset.right)
} }
// leftButtons // leftButtons
...@@ -421,8 +417,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -421,8 +417,7 @@ public class ImageCardView : MaterialPulseView {
h += "[\(k)]" h += "[\(k)]"
addSubview(b) layout.alignFromBottom(b, bottom: contentInset.bottom + leftButtonsInset.bottom)
Layout.alignFromBottom(self, child: b, bottom: contentInset.bottom + leftButtonsInset.bottom)
i += 1 i += 1
} }
...@@ -451,8 +446,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -451,8 +446,7 @@ public class ImageCardView : MaterialPulseView {
h += "-(right_left)-" h += "-(right_left)-"
} }
addSubview(b) layout.alignFromBottom(b, bottom: contentInset.bottom + rightButtonsInset.bottom)
Layout.alignFromBottom(self, child: b, bottom: contentInset.bottom + rightButtonsInset.bottom)
i -= 1 i -= 1
} }
......
...@@ -409,8 +409,7 @@ public class TextView: UITextView { ...@@ -409,8 +409,7 @@ public class TextView: UITextView {
internal func reloadView() { internal func reloadView() {
if let p = placeholderLabel { if let p = placeholderLabel {
removeConstraints(constraints) removeConstraints(constraints)
Layout.alignToParent(self, layout.align(p,
child: p,
top: textContainerInset.top, top: textContainerInset.top,
left: textContainerInset.left + textContainer.lineFragmentPadding, left: textContainerInset.left + textContainer.lineFragmentPadding,
bottom: textContainerInset.bottom, bottom: textContainerInset.bottom,
......
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