Commit eb4851dc by Daniel Dahan

updated MaterialLayout project to Layout project

parent d7c78951
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
location = "group:Programmatic/MaterialIcon/MaterialIcon.xcodeproj"> location = "group:Programmatic/MaterialIcon/MaterialIcon.xcodeproj">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:Programmatic/MaterialLayout/MaterialLayout.xcodeproj"> location = "group:Programmatic/Layout/Layout.xcodeproj">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:Programmatic/Grid/Grid.xcodeproj"> location = "group:Programmatic/Grid/Grid.xcodeproj">
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
<Workspace <Workspace
version = "1.0"> version = "1.0">
<FileRef <FileRef
location = "self:MaterialLayout.xcodeproj"> location = "self:Layout.xcodeproj">
</FileRef> </FileRef>
</Workspace> </Workspace>
...@@ -35,7 +35,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -35,7 +35,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow? var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds) window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = ViewController() window!.rootViewController = ViewController()
......
...@@ -31,9 +31,9 @@ ...@@ -31,9 +31,9 @@
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array> </array>
<key>UISupportedInterfaceOrientations~ipad</key> <key>UISupportedInterfaceOrientations~ipad</key>
<array> <array>
......
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
/** /**
Layout is an excellent tool to ease the use of AutoLayout. The following Layout is an excellent tool to ease the use of AutoLayout. The following
examples demonstrate laying out a collection of UILabel objects, both vertically examples demonstrate laying out a collection of UILabel objects in the vertical,
and horizontally. horizontal, anc center positions.
*/ */
import UIKit import UIKit
...@@ -41,9 +41,8 @@ class ViewController: UIViewController { ...@@ -41,9 +41,8 @@ class ViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
// prepareAlignToParentHorizontallyExample() prepareAlignToParentHorizontallyAndVerticallyExample()
// prepareAlignToParentVerticallyExample() // prepareCenterExample()
prepareCenterExample()
} }
/// General preparation statements. /// General preparation statements.
...@@ -52,7 +51,7 @@ class ViewController: UIViewController { ...@@ -52,7 +51,7 @@ class ViewController: UIViewController {
} }
/// Layout views horizontally with equal width. /// Layout views horizontally with equal width.
private func prepareAlignToParentHorizontallyExample() { private func prepareAlignToParentHorizontallyAndVerticallyExample() {
let label1: UILabel = UILabel() let label1: UILabel = UILabel()
label1.backgroundColor = MaterialColor.red.base label1.backgroundColor = MaterialColor.red.base
label1.text = "A" label1.text = "A"
...@@ -88,76 +87,39 @@ class ViewController: UIViewController { ...@@ -88,76 +87,39 @@ class ViewController: UIViewController {
} }
} }
/// Layout views vertically with equal height. // Lays out test views to the center of different axes
private func prepareAlignToParentVerticallyExample() { private func prepareCenterExample() {
let label1: UILabel = UILabel() let length: CGFloat = 100
label1.backgroundColor = MaterialColor.red.base
label1.text = "A"
label1.textAlignment = .Center
let label2: UILabel = UILabel() let labelCX = UILabel()
label2.backgroundColor = MaterialColor.green.base labelCX.backgroundColor = MaterialColor.grey.base
label2.text = "B" labelCX.text = "centerX"
label2.textAlignment = .Center labelCX.textAlignment = .Center
labelCX.layer.cornerRadius = length / 2.0
let label3: UILabel = UILabel() labelCX.clipsToBounds = true
label3.backgroundColor = MaterialColor.blue.base
label3.text = "C"
label3.textAlignment = .Center
let label4: UILabel = UILabel()
label4.backgroundColor = MaterialColor.yellow.base
label4.text = "D"
label4.textAlignment = .Center
let children: Array<UIView> = [label1, label2, label3, label4]
// Align the labels vertically with an equal height.
view.layout.vertically(children, top: 100, bottom: 100, spacing: 10)
// Align the labels horizontally with an equal width.
view.layout.horizontally(children, left: 100, right: 100)
// Print out the dimensions of the labels.
for v in children {
v.layoutIfNeeded()
print(v.frame)
}
}
// Lays out test views to the center of different axes
private func prepareCenterExample() {
let length: CGFloat = 100
let labelCX = UILabel()
labelCX.backgroundColor = MaterialColor.grey.base
labelCX.text = "centerX"
labelCX.textAlignment = .Center
labelCX.layer.cornerRadius = length / 2.0
labelCX.clipsToBounds = true
view.layout.size(labelCX, width: length, height: length) view.layout.size(labelCX, width: length, height: length)
view.layout.centerHorizontally(labelCX) view.layout.centerHorizontally(labelCX)
let labelCY = UILabel() let labelCY = UILabel()
labelCY.backgroundColor = MaterialColor.grey.base labelCY.backgroundColor = MaterialColor.grey.base
labelCY.text = "centerY" labelCY.text = "centerY"
labelCY.textAlignment = .Center labelCY.textAlignment = .Center
labelCY.layer.cornerRadius = length / 2.0 labelCY.layer.cornerRadius = length / 2.0
labelCY.clipsToBounds = true labelCY.clipsToBounds = true
view.layout.size(labelCY, width: length, height: length) view.layout.size(labelCY, width: length, height: length)
view.layout.centerVertically(labelCY) view.layout.centerVertically(labelCY)
let labelCXY = UILabel() let labelCXY = UILabel()
labelCXY.backgroundColor = MaterialColor.grey.base labelCXY.backgroundColor = MaterialColor.grey.base
labelCXY.text = "centerXY" labelCXY.text = "centerXY"
labelCXY.textAlignment = .Center labelCXY.textAlignment = .Center
labelCXY.layer.cornerRadius = length / 2.0 labelCXY.layer.cornerRadius = length / 2.0
labelCXY.clipsToBounds = true labelCXY.clipsToBounds = true
view.layout.size(labelCXY, width: length, height: length) view.layout.size(labelCXY, width: length, height: length)
view.layout.center(labelCXY) view.layout.center(labelCXY)
} }
} }
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