Commit 01fe9110 by Daniel Dahan

working NavigationBar

parent 2e247729
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
96162C6C1CA71C8700E3A235 /* VideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96162C6B1CA71C8700E3A235 /* VideoViewController.swift */; }; 96162C6C1CA71C8700E3A235 /* VideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96162C6B1CA71C8700E3A235 /* VideoViewController.swift */; };
96162C6E1CA7274E00E3A235 /* PhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */; }; 96162C6E1CA7274E00E3A235 /* PhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */; };
961F19321CE2579D008927C5 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 961F19311CE2579D008927C5 /* Material.framework */; };
961F19331CE2579D008927C5 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 961F19311CE2579D008927C5 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9663F9321C7A744600AF0965 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9311C7A744600AF0965 /* AppDelegate.swift */; }; 9663F9321C7A744600AF0965 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9311C7A744600AF0965 /* AppDelegate.swift */; };
9663F9341C7A744600AF0965 /* RecommendationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9331C7A744600AF0965 /* RecommendationViewController.swift */; }; 9663F9341C7A744600AF0965 /* RecommendationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9331C7A744600AF0965 /* RecommendationViewController.swift */; };
9663F9391C7A744600AF0965 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9663F9381C7A744600AF0965 /* Assets.xcassets */; }; 9663F9391C7A744600AF0965 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9663F9381C7A744600AF0965 /* Assets.xcassets */; };
...@@ -20,6 +18,8 @@ ...@@ -20,6 +18,8 @@
9663F94C1C7A74C700AF0965 /* AppMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */; }; 9663F94C1C7A74C700AF0965 /* AppMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */; };
9663F94E1C7A74EA00AF0965 /* AppLeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */; }; 9663F94E1C7A74EA00AF0965 /* AppLeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */; };
9663F9521C7A751D00AF0965 /* ItemViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9511C7A751D00AF0965 /* ItemViewController.swift */; }; 9663F9521C7A751D00AF0965 /* ItemViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9511C7A751D00AF0965 /* ItemViewController.swift */; };
9692C91F1CE4303F008C2766 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9692C91E1CE4303F008C2766 /* Material.framework */; };
9692C9201CE4303F008C2766 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9692C91E1CE4303F008C2766 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96CC08881C7FEBD60034FF84 /* RecipesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC08871C7FEBD60034FF84 /* RecipesViewController.swift */; }; 96CC08881C7FEBD60034FF84 /* RecipesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC08871C7FEBD60034FF84 /* RecipesViewController.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
961F19331CE2579D008927C5 /* Material.framework in Embed Frameworks */, 9692C9201CE4303F008C2766 /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
96162C6B1CA71C8700E3A235 /* VideoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoViewController.swift; sourceTree = "<group>"; }; 96162C6B1CA71C8700E3A235 /* VideoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoViewController.swift; sourceTree = "<group>"; };
96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoViewController.swift; sourceTree = "<group>"; }; 96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoViewController.swift; sourceTree = "<group>"; };
961F19311CE2579D008927C5 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/CosmicMind-hgvxkqfizbxkrsfcxbtlafgqkbve/Build/Products/Debug-iphoneos/Material.framework"; sourceTree = "<absolute>"; };
9663F92E1C7A744600AF0965 /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9663F92E1C7A744600AF0965 /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; };
9663F9311C7A744600AF0965 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 9663F9311C7A744600AF0965 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
9663F9331C7A744600AF0965 /* RecommendationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendationViewController.swift; sourceTree = "<group>"; }; 9663F9331C7A744600AF0965 /* RecommendationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendationViewController.swift; sourceTree = "<group>"; };
...@@ -52,6 +51,7 @@ ...@@ -52,6 +51,7 @@
9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppMenuViewController.swift; sourceTree = "<group>"; }; 9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppMenuViewController.swift; sourceTree = "<group>"; };
9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppLeftViewController.swift; sourceTree = "<group>"; }; 9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppLeftViewController.swift; sourceTree = "<group>"; };
9663F9511C7A751D00AF0965 /* ItemViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemViewController.swift; sourceTree = "<group>"; }; 9663F9511C7A751D00AF0965 /* ItemViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemViewController.swift; sourceTree = "<group>"; };
9692C91E1CE4303F008C2766 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/CosmicMind-hgvxkqfizbxkrsfcxbtlafgqkbve/Build/Products/Debug-iphoneos/Material.framework"; sourceTree = "<absolute>"; };
96CC08871C7FEBD60034FF84 /* RecipesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecipesViewController.swift; sourceTree = "<group>"; }; 96CC08871C7FEBD60034FF84 /* RecipesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecipesViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
961F19321CE2579D008927C5 /* Material.framework in Frameworks */, 9692C91F1CE4303F008C2766 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
9663F9251C7A744500AF0965 = { 9663F9251C7A744500AF0965 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
961F19311CE2579D008927C5 /* Material.framework */, 9692C91E1CE4303F008C2766 /* Material.framework */,
9663F9301C7A744600AF0965 /* App */, 9663F9301C7A744600AF0965 /* App */,
9663F92F1C7A744600AF0965 /* Products */, 9663F92F1C7A744600AF0965 /* Products */,
); );
......
...@@ -111,11 +111,11 @@ class ItemViewController: UIViewController { ...@@ -111,11 +111,11 @@ class ItemViewController: UIViewController {
/// Prepares the navigationItem. /// Prepares the navigationItem.
private func prepareNavigationItem() { private func prepareNavigationItem() {
navigationItem.title = "Item" navigationItem.titleLabel.text = "Itempppyyggg"
navigationItem.titleLabel.textAlignment = .Left navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.textColor = MaterialColor.white navigationItem.titleLabel.textColor = MaterialColor.white
navigationItem.detail = "January 22, 2016" navigationItem.detailLabel.text = "January 22pppyyyggg, 2016"
navigationItem.detailLabel.textAlignment = .Left navigationItem.detailLabel.textAlignment = .Left
navigationItem.detailLabel.textColor = MaterialColor.white navigationItem.detailLabel.textColor = MaterialColor.white
...@@ -141,22 +141,22 @@ class ItemViewController: UIViewController { ...@@ -141,22 +141,22 @@ class ItemViewController: UIViewController {
imageCardView.cornerRadiusPreset = .None imageCardView.cornerRadiusPreset = .None
imageCardView.maxImageHeight = 300 imageCardView.maxImageHeight = 300
imageCardView.titleLabel = UILabel() // imageCardView.titleLabel = UILabel()
imageCardView.titleLabel?.text = data["title"] as? String // imageCardView.titleLabel?.text = data["title"] as? String
imageCardView.titleLabel?.textColor = MaterialColor.grey.darken4 // imageCardView.titleLabel?.textColor = MaterialColor.grey.darken4
imageCardView.titleLabel?.font = RobotoFont.regularWithSize(20) // imageCardView.titleLabel?.font = RobotoFont.regularWithSize(20)
//
let detailLabel: UILabel = UILabel() let detailLabel: UILabel = UILabel()
detailLabel.text = data["detail"] as? String detailLabel.text = data["detail"] as? String
detailLabel.textColor = MaterialColor.grey.darken2 detailLabel.textColor = MaterialColor.grey.darken2
detailLabel.font = RobotoFont.regular detailLabel.font = RobotoFont.regular
detailLabel.numberOfLines = 0 detailLabel.numberOfLines = 0
imageCardView.contentView = detailLabel imageCardView.contentView = detailLabel
imageCardView.contentViewInset.top = 52 imageCardView.contentViewInset.top = 52
//
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) scrollView.addSubview(imageCardView)
} }
......
...@@ -244,8 +244,7 @@ class RecipesViewController: UIViewController { ...@@ -244,8 +244,7 @@ class RecipesViewController: UIViewController {
/// Prepares the navigationItem. /// Prepares the navigationItem.
private func prepareNavigationItem() { private func prepareNavigationItem() {
navigationItem.title = "Recipes" navigationItem.titleLabel.text = "Recipesqqggyy"
navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.textColor = MaterialColor.white navigationItem.titleLabel.textColor = MaterialColor.white
navigationItem.leftControls = [menuButton] navigationItem.leftControls = [menuButton]
......
...@@ -224,7 +224,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg ...@@ -224,7 +224,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
view.addSubview(captureView) view.addSubview(captureView)
captureView.tapToFocusEnabled = true captureView.tapToFocusEnabled = true
captureView.tapToExposeEnabled = true captureView.tapToExposeEnabled = true
captureView.translatesAutoresizingMaskIntoConstraints = false
captureView.delegate = self captureView.delegate = self
captureView.captureSession.delegate = self captureView.captureSession.delegate = self
MaterialLayout.alignToParent(view, child: captureView) MaterialLayout.alignToParent(view, child: captureView)
...@@ -283,7 +282,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg ...@@ -283,7 +282,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
let img4: UIImage? = UIImage(named: "ic_photo_camera_white_36pt") let img4: UIImage? = UIImage(named: "ic_photo_camera_white_36pt")
cameraButton.width = 72 cameraButton.width = 72
cameraButton.height = 72 cameraButton.height = 72
cameraButton.pulseColor = nil
cameraButton.setImage(img4, forState: .Normal) cameraButton.setImage(img4, forState: .Normal)
cameraButton.setImage(img4, forState: .Highlighted) cameraButton.setImage(img4, forState: .Highlighted)
...@@ -297,7 +295,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg ...@@ -297,7 +295,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
let img5: UIImage? = UIImage(named: "ic_videocam_white_36pt") let img5: UIImage? = UIImage(named: "ic_videocam_white_36pt")
videoButton.width = 72 videoButton.width = 72
videoButton.height = 72 videoButton.height = 72
videoButton.pulseColor = nil
videoButton.setImage(img5, forState: .Normal) videoButton.setImage(img5, forState: .Normal)
videoButton.setImage(img5, forState: .Highlighted) videoButton.setImage(img5, forState: .Highlighted)
...@@ -309,7 +306,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg ...@@ -309,7 +306,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
*/ */
private func prepareSwitchCamerasButton() { private func prepareSwitchCamerasButton() {
let img: UIImage? = UIImage(named: "ic_camera_front_white") let img: UIImage? = UIImage(named: "ic_camera_front_white")
switchCamerasButton.pulseColor = nil
switchCamerasButton.setImage(img, forState: .Normal) switchCamerasButton.setImage(img, forState: .Normal)
switchCamerasButton.setImage(img, forState: .Highlighted) switchCamerasButton.setImage(img, forState: .Highlighted)
...@@ -321,7 +317,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg ...@@ -321,7 +317,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
*/ */
private func prepareFlashButton() { private func prepareFlashButton() {
let img: UIImage? = UIImage(named: "ic_flash_auto_white") let img: UIImage? = UIImage(named: "ic_flash_auto_white")
flashButton.pulseColor = nil
flashButton.setImage(img, forState: .Normal) flashButton.setImage(img, forState: .Normal)
flashButton.setImage(img, forState: .Highlighted) flashButton.setImage(img, forState: .Highlighted)
......
...@@ -80,7 +80,6 @@ class ViewController: UIViewController { ...@@ -80,7 +80,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout. // To support orientation changes, use MaterialLayout.
view.addSubview(cardView) view.addSubview(cardView)
cardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: cardView, top: 100) MaterialLayout.alignFromTop(view, child: cardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20) MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
} }
...@@ -89,7 +88,6 @@ class ViewController: UIViewController { ...@@ -89,7 +88,6 @@ class ViewController: UIViewController {
let cardView: CardView = CardView() let cardView: CardView = CardView()
cardView.divider = false cardView.divider = false
cardView.backgroundColor = MaterialColor.red.base cardView.backgroundColor = MaterialColor.red.base
cardView.pulseColor = nil
cardView.image = UIImage(named: "Material-iTunesArtWork")?.resize(toHeight: 75) cardView.image = UIImage(named: "Material-iTunesArtWork")?.resize(toHeight: 75)
cardView.contentsGravityPreset = .BottomRight cardView.contentsGravityPreset = .BottomRight
...@@ -121,7 +119,6 @@ class ViewController: UIViewController { ...@@ -121,7 +119,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout. // To support orientation changes, use MaterialLayout.
view.addSubview(cardView) view.addSubview(cardView)
cardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: cardView, top: 100) MaterialLayout.alignFromTop(view, child: cardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20) MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
} }
...@@ -162,7 +159,6 @@ class ViewController: UIViewController { ...@@ -162,7 +159,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout. // To support orientation changes, use MaterialLayout.
view.addSubview(cardView) view.addSubview(cardView)
cardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: cardView, top: 100) MaterialLayout.alignFromTop(view, child: cardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20) MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
} }
...@@ -170,7 +166,6 @@ class ViewController: UIViewController { ...@@ -170,7 +166,6 @@ class ViewController: UIViewController {
private func prepareCardViewButtonBarExample() { private func prepareCardViewButtonBarExample() {
let cardView: CardView = CardView() let cardView: CardView = CardView()
cardView.divider = false cardView.divider = false
cardView.pulseColor = nil
cardView.backgroundColor = MaterialColor.blueGrey.darken4 cardView.backgroundColor = MaterialColor.blueGrey.darken4
// Search button. // Search button.
...@@ -203,7 +198,6 @@ class ViewController: UIViewController { ...@@ -203,7 +198,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout. // To support orientation changes, use MaterialLayout.
view.addSubview(cardView) view.addSubview(cardView)
cardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: cardView, top: 100) MaterialLayout.alignFromTop(view, child: cardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20) MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
} }
......
...@@ -84,7 +84,6 @@ class ViewController: UIViewController { ...@@ -84,7 +84,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout. // To support orientation changes, use MaterialLayout.
view.addSubview(imageCardView) view.addSubview(imageCardView)
imageCardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: imageCardView, top: 100) MaterialLayout.alignFromTop(view, child: imageCardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: imageCardView, left: 20, right: 20) MaterialLayout.alignToParentHorizontally(view, child: imageCardView, left: 20, right: 20)
} }
...@@ -134,7 +133,6 @@ class ViewController: UIViewController { ...@@ -134,7 +133,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout. // To support orientation changes, use MaterialLayout.
view.addSubview(imageCardView) view.addSubview(imageCardView)
imageCardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: imageCardView, top: 100) MaterialLayout.alignFromTop(view, child: imageCardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: imageCardView, left: 20, right: 20) MaterialLayout.alignToParentHorizontally(view, child: imageCardView, left: 20, right: 20)
} }
......
...@@ -87,7 +87,6 @@ class ViewController: UIViewController { ...@@ -87,7 +87,6 @@ class ViewController: UIViewController {
// Use MaterialLayout to easily align the tableView. // Use MaterialLayout to easily align the tableView.
view.addSubview(collectionView) view.addSubview(collectionView)
collectionView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: collectionView) MaterialLayout.alignToParent(view, child: collectionView)
} }
} }
......
...@@ -46,27 +46,22 @@ class ViewController: UIViewController { ...@@ -46,27 +46,22 @@ class ViewController: UIViewController {
/// Prepares the MaterialDepth. /// Prepares the MaterialDepth.
private func prepareMaterialDepth() { private func prepareMaterialDepth() {
let v1: MaterialView = MaterialView() let v1: MaterialView = MaterialView()
v1.translatesAutoresizingMaskIntoConstraints = false
v1.depth = .Depth1 v1.depth = .Depth1
view.addSubview(v1) view.addSubview(v1)
let v2: MaterialView = MaterialView() let v2: MaterialView = MaterialView()
v2.translatesAutoresizingMaskIntoConstraints = false
v2.depth = .Depth2 v2.depth = .Depth2
view.addSubview(v2) view.addSubview(v2)
let v3: MaterialView = MaterialView() let v3: MaterialView = MaterialView()
v3.translatesAutoresizingMaskIntoConstraints = false
v3.depth = .Depth3 v3.depth = .Depth3
view.addSubview(v3) view.addSubview(v3)
let v4: MaterialView = MaterialView() let v4: MaterialView = MaterialView()
v4.translatesAutoresizingMaskIntoConstraints = false
v4.depth = .Depth4 v4.depth = .Depth4
view.addSubview(v4) view.addSubview(v4)
let v5: MaterialView = MaterialView() let v5: MaterialView = MaterialView()
v5.translatesAutoresizingMaskIntoConstraints = false
v5.depth = .Depth5 v5.depth = .Depth5
view.addSubview(v5) view.addSubview(v5)
......
...@@ -109,7 +109,6 @@ class ViewController: UIViewController { ...@@ -109,7 +109,6 @@ class ViewController: UIViewController {
tableView.registerClass(MaterialTableViewCell.self, forCellReuseIdentifier: "Cell") tableView.registerClass(MaterialTableViewCell.self, forCellReuseIdentifier: "Cell")
tableView.dataSource = self tableView.dataSource = self
tableView.delegate = self tableView.delegate = self
tableView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(tableView) view.addSubview(tableView)
......
...@@ -53,28 +53,24 @@ class ViewController: UIViewController { ...@@ -53,28 +53,24 @@ class ViewController: UIViewController {
/// Layout views horizontally with equal width. /// Layout views horizontally with equal width.
private func prepareAlignToParentHorizontallyExample() { private func prepareAlignToParentHorizontallyExample() {
let label1: UILabel = UILabel() let label1: UILabel = UILabel()
label1.translatesAutoresizingMaskIntoConstraints = false
label1.backgroundColor = MaterialColor.red.base label1.backgroundColor = MaterialColor.red.base
label1.text = "A" label1.text = "A"
label1.textAlignment = .Center label1.textAlignment = .Center
view.addSubview(label1) view.addSubview(label1)
let label2: UILabel = UILabel() let label2: UILabel = UILabel()
label2.translatesAutoresizingMaskIntoConstraints = false
label2.backgroundColor = MaterialColor.green.base label2.backgroundColor = MaterialColor.green.base
label2.text = "B" label2.text = "B"
label2.textAlignment = .Center label2.textAlignment = .Center
view.addSubview(label2) view.addSubview(label2)
let label3: UILabel = UILabel() let label3: UILabel = UILabel()
label3.translatesAutoresizingMaskIntoConstraints = false
label3.backgroundColor = MaterialColor.blue.base label3.backgroundColor = MaterialColor.blue.base
label3.text = "C" label3.text = "C"
label3.textAlignment = .Center label3.textAlignment = .Center
view.addSubview(label3) view.addSubview(label3)
let label4: UILabel = UILabel() let label4: UILabel = UILabel()
label4.translatesAutoresizingMaskIntoConstraints = false
label4.backgroundColor = MaterialColor.yellow.base label4.backgroundColor = MaterialColor.yellow.base
label4.text = "D" label4.text = "D"
label4.textAlignment = .Center label4.textAlignment = .Center
...@@ -103,28 +99,24 @@ class ViewController: UIViewController { ...@@ -103,28 +99,24 @@ class ViewController: UIViewController {
/// Layout views vertically with equal height. /// Layout views vertically with equal height.
private func prepareAlignToParentVerticallyExample() { private func prepareAlignToParentVerticallyExample() {
let label1: UILabel = UILabel() let label1: UILabel = UILabel()
label1.translatesAutoresizingMaskIntoConstraints = false
label1.backgroundColor = MaterialColor.red.base label1.backgroundColor = MaterialColor.red.base
label1.text = "A" label1.text = "A"
label1.textAlignment = .Center label1.textAlignment = .Center
view.addSubview(label1) view.addSubview(label1)
let label2: UILabel = UILabel() let label2: UILabel = UILabel()
label2.translatesAutoresizingMaskIntoConstraints = false
label2.backgroundColor = MaterialColor.green.base label2.backgroundColor = MaterialColor.green.base
label2.text = "B" label2.text = "B"
label2.textAlignment = .Center label2.textAlignment = .Center
view.addSubview(label2) view.addSubview(label2)
let label3: UILabel = UILabel() let label3: UILabel = UILabel()
label3.translatesAutoresizingMaskIntoConstraints = false
label3.backgroundColor = MaterialColor.blue.base label3.backgroundColor = MaterialColor.blue.base
label3.text = "C" label3.text = "C"
label3.textAlignment = .Center label3.textAlignment = .Center
view.addSubview(label3) view.addSubview(label3)
let label4: UILabel = UILabel() let label4: UILabel = UILabel()
label4.translatesAutoresizingMaskIntoConstraints = false
label4.backgroundColor = MaterialColor.yellow.base label4.backgroundColor = MaterialColor.yellow.base
label4.text = "D" label4.text = "D"
label4.textAlignment = .Center label4.textAlignment = .Center
......
...@@ -51,10 +51,8 @@ class ViewController: UIViewController, MaterialSwitchDelegate { ...@@ -51,10 +51,8 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
view.addSubview(topView) view.addSubview(topView)
topView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bottomView) view.addSubview(bottomView)
bottomView.translatesAutoresizingMaskIntoConstraints = false
bottomView.backgroundColor = MaterialColor.grey.darken4 bottomView.backgroundColor = MaterialColor.grey.darken4
MaterialLayout.alignToParentHorizontally(view, child: topView) MaterialLayout.alignToParentHorizontally(view, child: topView)
...@@ -66,18 +64,15 @@ class ViewController: UIViewController, MaterialSwitchDelegate { ...@@ -66,18 +64,15 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
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
c1.translatesAutoresizingMaskIntoConstraints = false
topView.addSubview(c1) 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
c2.translatesAutoresizingMaskIntoConstraints = false
topView.addSubview(c2) 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
c3.translatesAutoresizingMaskIntoConstraints = false
topView.addSubview(c3) topView.addSubview(c3)
MaterialLayout.alignToParentHorizontally(topView, child: c1) MaterialLayout.alignToParentHorizontally(topView, child: c1)
...@@ -90,18 +85,15 @@ class ViewController: UIViewController, MaterialSwitchDelegate { ...@@ -90,18 +85,15 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
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
c1.translatesAutoresizingMaskIntoConstraints = false
bottomView.addSubview(c1) bottomView.addSubview(c1)
let c2: MaterialSwitch = MaterialSwitch(state: .On) let c2: MaterialSwitch = MaterialSwitch(state: .On)
c2.delegate = self c2.delegate = self
c2.translatesAutoresizingMaskIntoConstraints = false
bottomView.addSubview(c2) 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
c3.translatesAutoresizingMaskIntoConstraints = false
bottomView.addSubview(c3) bottomView.addSubview(c3)
MaterialLayout.alignToParentHorizontally(bottomView, child: c1) MaterialLayout.alignToParentHorizontally(bottomView, child: c1)
......
...@@ -128,7 +128,6 @@ class ViewController: UIViewController { ...@@ -128,7 +128,6 @@ class ViewController: UIViewController {
private func prepareFabMenuExample() { private func prepareFabMenuExample() {
var image: UIImage? = UIImage(named: "ic_add_white") var image: UIImage? = UIImage(named: "ic_add_white")
let btn1: FabButton = FabButton() let btn1: FabButton = FabButton()
btn1.pulseColor = nil
btn1.setImage(image, forState: .Normal) btn1.setImage(image, forState: .Normal)
btn1.setImage(image, forState: .Highlighted) btn1.setImage(image, forState: .Highlighted)
btn1.addTarget(self, action: #selector(handleFabMenu), forControlEvents: .TouchUpInside) btn1.addTarget(self, action: #selector(handleFabMenu), forControlEvents: .TouchUpInside)
......
...@@ -85,7 +85,6 @@ class ViewController: UIViewController { ...@@ -85,7 +85,6 @@ class ViewController: UIViewController {
let btn1: FabButton = FabButton() let btn1: FabButton = FabButton()
btn1.depth = .None btn1.depth = .None
btn1.tintColor = MaterialColor.blue.accent3 btn1.tintColor = MaterialColor.blue.accent3
btn1.pulseColor = nil
btn1.borderColor = MaterialColor.blue.accent3 btn1.borderColor = MaterialColor.blue.accent3
btn1.backgroundColor = MaterialColor.white btn1.backgroundColor = MaterialColor.white
btn1.borderWidth = 1 btn1.borderWidth = 1
...@@ -139,7 +138,6 @@ class ViewController: UIViewController { ...@@ -139,7 +138,6 @@ class ViewController: UIViewController {
menuView.menu.views = [btn1, btn2, btn3, btn4] menuView.menu.views = [btn1, btn2, btn3, btn4]
view.addSubview(menuView) view.addSubview(menuView)
menuView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.size(view, child: menuView, width: diameter, height: diameter) MaterialLayout.size(view, child: menuView, width: diameter, height: diameter)
MaterialLayout.alignFromBottomLeft(view, child: menuView, bottom: 16, left: (view.bounds.width - diameter) / 2) MaterialLayout.alignFromBottomLeft(view, child: menuView, bottom: 16, left: (view.bounds.width - diameter) / 2)
} }
......
...@@ -136,7 +136,6 @@ class AppMenuViewController: MenuViewController { ...@@ -136,7 +136,6 @@ class AppMenuViewController: MenuViewController {
menuView.menu.views = [btn1, btn2, btn3, btn4] menuView.menu.views = [btn1, btn2, btn3, btn4]
view.addSubview(menuView) view.addSubview(menuView)
menuView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.size(view, child: menuView, width: baseViewSize.width, height: baseViewSize.height) MaterialLayout.size(view, child: menuView, width: baseViewSize.width, height: baseViewSize.height)
MaterialLayout.alignFromBottomRight(view, child: menuView, bottom: menuViewInset, right: menuViewInset) MaterialLayout.alignFromBottomRight(view, child: menuView, bottom: menuViewInset, right: menuViewInset)
} }
......
...@@ -76,7 +76,6 @@ class AppLeftViewController: UIViewController { ...@@ -76,7 +76,6 @@ class AppLeftViewController: UIViewController {
// Use MaterialLayout to easily align the tableView. // Use MaterialLayout to easily align the tableView.
view.addSubview(tableView) view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: tableView) MaterialLayout.alignToParent(view, child: tableView)
} }
} }
......
...@@ -84,7 +84,6 @@ class ViewController: UIViewController { ...@@ -84,7 +84,6 @@ class ViewController: UIViewController {
/// Prepares the CardView. /// Prepares the CardView.
func prepareCardView() { func prepareCardView() {
let cardView: CardView = CardView() let cardView: CardView = CardView()
cardView.pulseColor = nil
cardView.backgroundColor = MaterialColor.grey.lighten5 cardView.backgroundColor = MaterialColor.grey.lighten5
cardView.cornerRadiusPreset = .Radius1 cardView.cornerRadiusPreset = .Radius1
cardView.divider = false cardView.divider = false
...@@ -117,7 +116,6 @@ class ViewController: UIViewController { ...@@ -117,7 +116,6 @@ class ViewController: UIViewController {
cardView.leftButtons = [closeButton] cardView.leftButtons = [closeButton]
cardView.rightButtons = [settingButton] cardView.rightButtons = [settingButton]
cardView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(cardView) view.addSubview(cardView)
MaterialLayout.alignToParent(view, child: cardView, left: 10, right: 10, top: 100, bottom: 100) MaterialLayout.alignToParent(view, child: cardView, left: 10, right: 10, top: 100, bottom: 100)
} }
......
...@@ -65,7 +65,6 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -65,7 +65,6 @@ class ViewController: UIViewController, TextFieldDelegate {
/// Prepares the resign responder button. /// Prepares the resign responder button.
private func prepareResignResponderButton() { private func prepareResignResponderButton() {
let btn: RaisedButton = RaisedButton() let btn: RaisedButton = RaisedButton()
btn.translatesAutoresizingMaskIntoConstraints = false
btn.addTarget(self, action: #selector(handleResignResponderButton), forControlEvents: .TouchUpInside) btn.addTarget(self, action: #selector(handleResignResponderButton), forControlEvents: .TouchUpInside)
btn.setTitle("Resign", forState: .Normal) btn.setTitle("Resign", forState: .Normal)
btn.setTitleColor(MaterialColor.blue.base, forState: .Normal) btn.setTitleColor(MaterialColor.blue.base, forState: .Normal)
...@@ -93,8 +92,6 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -93,8 +92,6 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField.textAlignment = .Center nameField.textAlignment = .Center
nameField.clearButtonMode = .WhileEditing nameField.clearButtonMode = .WhileEditing
// The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly.
nameField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(nameField) 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
...@@ -129,8 +126,6 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -129,8 +126,6 @@ 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)
// The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly.
passwordField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(passwordField) 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
......
...@@ -76,7 +76,6 @@ class ViewController: UIViewController, TextDelegate { ...@@ -76,7 +76,6 @@ class ViewController: UIViewController, TextDelegate {
textView.titleLabelActiveColor = MaterialColor.blue.accent3 textView.titleLabelActiveColor = MaterialColor.blue.accent3
view.addSubview(textView) view.addSubview(textView)
textView!.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: textView!, top: 124, left: 24, bottom: 24, right: 24) MaterialLayout.alignToParent(view, child: textView!, top: 124, left: 24, bottom: 24, right: 24)
} }
......
...@@ -44,7 +44,6 @@ class RootViewController: UIViewController { ...@@ -44,7 +44,6 @@ class RootViewController: UIViewController {
fabButton.addTarget(self, action: #selector(handleFabButton), forControlEvents: .TouchUpInside) fabButton.addTarget(self, action: #selector(handleFabButton), forControlEvents: .TouchUpInside)
view.addSubview(fabButton) view.addSubview(fabButton)
fabButton.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromBottomRight(view, child: fabButton, bottom: 16, right: 16) MaterialLayout.alignFromBottomRight(view, child: fabButton, bottom: 16, right: 16)
MaterialLayout.size(view, child: fabButton, width: 64, height: 64) MaterialLayout.size(view, child: fabButton, width: 64, height: 64)
} }
......
...@@ -31,38 +31,27 @@ ...@@ -31,38 +31,27 @@
import UIKit import UIKit
public struct MaterialLayout { public struct MaterialLayout {
/** /// Width
:name: width
*/
public static func width(parent: UIView, child: UIView, width: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func width(parent: UIView, child: UIView, width: CGFloat = 0, options: NSLayoutFormatOptions = []) {
let metrics: Dictionary<String, AnyObject> = ["width" : width] let metrics: Dictionary<String, AnyObject> = ["width" : width]
let views: Dictionary<String, AnyObject> = ["child" : child] let views: Dictionary<String, AnyObject> = ["child" : child]
child.translatesAutoresizingMaskIntoConstraints = false
parent.addConstraints(constraint("H:[child(width)]", options: options, metrics: metrics, views: views)) parent.addConstraints(constraint("H:[child(width)]", options: options, metrics: metrics, views: views))
} }
/** /// Height
:name: height
*/
public static func height(parent: UIView, child: UIView, height: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func height(parent: UIView, child: UIView, height: CGFloat = 0, options: NSLayoutFormatOptions = []) {
let metrics: Dictionary<String, AnyObject> = ["height" : height] let metrics: Dictionary<String, AnyObject> = ["height" : height]
let views: Dictionary<String, AnyObject> = ["child" : child] let views: Dictionary<String, AnyObject> = ["child" : child]
child.translatesAutoresizingMaskIntoConstraints = false
parent.addConstraints(constraint("V:[child(height)]", options: options, metrics: metrics, views: views)) parent.addConstraints(constraint("V:[child(height)]", options: options, metrics: metrics, views: views))
} }
/** /// Size
:name: size
*/
public static func size(parent: UIView, child: UIView, width: CGFloat = 0, height: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func size(parent: UIView, child: UIView, width: CGFloat = 0, height: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.width(parent, child: child, width: width) MaterialLayout.width(parent, child: child, width: width)
MaterialLayout.height(parent, child: child, height: height) MaterialLayout.height(parent, child: child, height: height)
} }
/** /// AlignToParentHorizontally
:name: alignToParentHorizontally
*/
public static func alignToParentHorizontally(parent: UIView, children: Array<UIView>, left: CGFloat = 0, right: CGFloat = 0, spacing: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignToParentHorizontally(parent: UIView, children: Array<UIView>, left: CGFloat = 0, right: CGFloat = 0, spacing: CGFloat = 0, options: NSLayoutFormatOptions = []) {
if 0 < children.count { if 0 < children.count {
var format: String = "H:|-(left)-" var format: String = "H:|-(left)-"
...@@ -73,15 +62,12 @@ public struct MaterialLayout { ...@@ -73,15 +62,12 @@ public struct MaterialLayout {
i += 1 i += 1
views[k] = v views[k] = v
format += i > children.count ? "[\(k)(==view1)]-(right)-|" : "[\(k)(==view1)]-(spacing)-" format += i > children.count ? "[\(k)(==view1)]-(right)-|" : "[\(k)(==view1)]-(spacing)-"
v.translatesAutoresizingMaskIntoConstraints = false
} }
parent.addConstraints(constraint(format, options: options, metrics: ["left" : left, "right": right, "spacing": spacing], views: views)) parent.addConstraints(constraint(format, options: options, metrics: ["left" : left, "right": right, "spacing": spacing], views: views))
} }
} }
/** /// AlignToParentVertically
:name: alignToParentVertically
*/
public static func alignToParentVertically(parent: UIView, children: Array<UIView>, top: CGFloat = 0, bottom: CGFloat = 0, spacing: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignToParentVertically(parent: UIView, children: Array<UIView>, top: CGFloat = 0, bottom: CGFloat = 0, spacing: CGFloat = 0, options: NSLayoutFormatOptions = []) {
if 0 < children.count { if 0 < children.count {
var format: String = "V:|-(top)-" var format: String = "V:|-(top)-"
...@@ -92,109 +78,78 @@ public struct MaterialLayout { ...@@ -92,109 +78,78 @@ public struct MaterialLayout {
i += 1 i += 1
views[k] = v views[k] = v
format += i > children.count ? "[\(k)(==view1)]-(bottom)-|" : "[\(k)(==view1)]-(spacing)-" format += i > children.count ? "[\(k)(==view1)]-(bottom)-|" : "[\(k)(==view1)]-(spacing)-"
v.translatesAutoresizingMaskIntoConstraints = false
} }
parent.addConstraints(constraint(format, options: options, metrics: ["top" : top, "bottom": bottom, "spacing": spacing], views: views)) parent.addConstraints(constraint(format, options: options, metrics: ["top" : top, "bottom": bottom, "spacing": spacing], views: views))
} }
} }
/** /// AlignToParentHorizontally
:name: alignToParentHorizontally
*/
public static func alignToParentHorizontally(parent: UIView, child: UIView, left: CGFloat = 0, right: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignToParentHorizontally(parent: UIView, child: UIView, left: CGFloat = 0, right: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
parent.addConstraints(constraint("H:|-(left)-[child]-(right)-|", options: options, metrics: ["left": left, "right": right], views: ["child" : child])) parent.addConstraints(constraint("H:|-(left)-[child]-(right)-|", options: options, metrics: ["left": left, "right": right], views: ["child" : child]))
} }
/** /// AlignToParentVertically
:name: alignToParentVertically
*/
public static func alignToParentVertically(parent: UIView, child: UIView, top: CGFloat = 0, bottom: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignToParentVertically(parent: UIView, child: UIView, top: CGFloat = 0, bottom: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
parent.addConstraints(constraint("V:|-(top)-[child]-(bottom)-|", options: options, metrics: ["bottom": bottom, "top": top], views: ["child" : child])) parent.addConstraints(constraint("V:|-(top)-[child]-(bottom)-|", options: options, metrics: ["bottom": bottom, "top": top], views: ["child" : child]))
} }
/** /// AlignToParent
:name: alignToParent
*/
public static func alignToParent(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignToParent(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
alignToParentHorizontally(parent, child: child, left: left, right: right) alignToParentHorizontally(parent, child: child, left: left, right: right)
alignToParentVertically(parent, child: child, top: top, bottom: bottom) alignToParentVertically(parent, child: child, top: top, bottom: bottom)
} }
/** /// AlignFromTopLeft
:name: alignFromTopLeft
*/
public static func alignFromTopLeft(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignFromTopLeft(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
alignFromTop(parent, child: child, top: top) alignFromTop(parent, child: child, top: top)
alignFromLeft(parent, child: child, left: left) alignFromLeft(parent, child: child, left: left)
} }
/** /// AlignFromTopRight
:name: alignFromTopRight
*/
public static func alignFromTopRight(parent: UIView, child: UIView, top: CGFloat = 0, right: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignFromTopRight(parent: UIView, child: UIView, top: CGFloat = 0, right: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
alignFromTop(parent, child: child, top: top) alignFromTop(parent, child: child, top: top)
alignFromRight(parent, child: child, right: right) alignFromRight(parent, child: child, right: right)
} }
/** /// AlignFromBottomLeft
:name: alignFromBottomLeft
*/
public static func alignFromBottomLeft(parent: UIView, child: UIView, bottom: CGFloat = 0, left: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignFromBottomLeft(parent: UIView, child: UIView, bottom: CGFloat = 0, left: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
alignFromBottom(parent, child: child, bottom: bottom) alignFromBottom(parent, child: child, bottom: bottom)
alignFromLeft(parent, child: child, left: left) alignFromLeft(parent, child: child, left: left)
} }
/** /// AlignFromBottomRight
:name: alignFromBottomRight
*/
public static func alignFromBottomRight(parent: UIView, child: UIView, bottom: CGFloat = 0, right: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignFromBottomRight(parent: UIView, child: UIView, bottom: CGFloat = 0, right: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
alignFromBottom(parent, child: child, bottom: bottom) alignFromBottom(parent, child: child, bottom: bottom)
alignFromRight(parent, child: child, right: right) alignFromRight(parent, child: child, right: right)
} }
/** /// AlignFromTop
:name: alignFromTop
*/
public static func alignFromTop(parent: UIView, child: UIView, top: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignFromTop(parent: UIView, child: UIView, top: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
parent.addConstraints(constraint("V:|-(top)-[child]", options: options, metrics: ["top" : top], views: ["child" : child])) parent.addConstraints(constraint("V:|-(top)-[child]", options: options, metrics: ["top" : top], views: ["child" : child]))
} }
/** /// AlignFromLeft
:name: alignFromLeft
*/
public static func alignFromLeft(parent: UIView, child: UIView, left: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignFromLeft(parent: UIView, child: UIView, left: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
parent.addConstraints(constraint("H:|-(left)-[child]", options: options, metrics: ["left" : left], views: ["child" : child])) parent.addConstraints(constraint("H:|-(left)-[child]", options: options, metrics: ["left" : left], views: ["child" : child]))
} }
/** /// AlignFromBottom
:name: alignFromBottom
*/
public static func alignFromBottom(parent: UIView, child: UIView, bottom: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignFromBottom(parent: UIView, child: UIView, bottom: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
parent.addConstraints(constraint("V:[child]-(bottom)-|", options: options, metrics: ["bottom" : bottom], views: ["child" : child])) parent.addConstraints(constraint("V:[child]-(bottom)-|", options: options, metrics: ["bottom" : bottom], views: ["child" : child]))
} }
/** /// AlignFromRight
:name: alignFromRight
*/
public static func alignFromRight(parent: UIView, child: UIView, right: CGFloat = 0, options: NSLayoutFormatOptions = []) { public static func alignFromRight(parent: UIView, child: UIView, right: CGFloat = 0, options: NSLayoutFormatOptions = []) {
child.translatesAutoresizingMaskIntoConstraints = false
parent.addConstraints(constraint("H:[child]-(right)-|", options: options, metrics: ["right" : right], views: ["child" : child])) parent.addConstraints(constraint("H:[child]-(right)-|", options: options, metrics: ["right" : right], views: ["child" : child]))
} }
/** /// Constraint
:name: constraint
*/
public static func constraint(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, AnyObject>?, views: Dictionary<String, AnyObject>) -> Array<NSLayoutConstraint> { public static func constraint(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, AnyObject>?, views: Dictionary<String, AnyObject>) -> Array<NSLayoutConstraint> {
for (_, a) in views {
if let v: UIView = a as? UIView {
v.translatesAutoresizingMaskIntoConstraints = false
}
}
return NSLayoutConstraint.constraintsWithVisualFormat( return NSLayoutConstraint.constraintsWithVisualFormat(
format, format,
options: options, options: options,
......
...@@ -30,6 +30,13 @@ ...@@ -30,6 +30,13 @@
import UIKit import UIKit
/// NavigationBar styles.
public enum NavigationBarStyle {
case Tiny
case Default
case Medium
}
public extension UINavigationBar { public extension UINavigationBar {
/// Device status bar style. /// Device status bar style.
public var statusBarStyle: UIStatusBarStyle { public var statusBarStyle: UIStatusBarStyle {
...@@ -44,6 +51,9 @@ public extension UINavigationBar { ...@@ -44,6 +51,9 @@ public extension UINavigationBar {
@IBDesignable @IBDesignable
public class NavigationBar : UINavigationBar { public class NavigationBar : UINavigationBar {
/// NavigationBarStyle value.
public var navigationBarStyle: NavigationBarStyle = .Default
/// Will render the view. /// Will render the view.
public var willRenderView: Bool { public var willRenderView: Bool {
return 0 < width return 0 < width
...@@ -273,7 +283,14 @@ public class NavigationBar : UINavigationBar { ...@@ -273,7 +283,14 @@ public class NavigationBar : UINavigationBar {
} }
public override func intrinsicContentSize() -> CGSize { public override func intrinsicContentSize() -> CGSize {
return CGSizeMake(MaterialDevice.width, 44) switch navigationBarStyle {
case .Tiny:
return CGSizeMake(MaterialDevice.width, 32)
case .Default:
return CGSizeMake(MaterialDevice.width, 44)
case .Medium:
return CGSizeMake(MaterialDevice.width, 56)
}
} }
public override func sizeThatFits(size: CGSize) -> CGSize { public override func sizeThatFits(size: CGSize) -> CGSize {
...@@ -302,41 +319,38 @@ public class NavigationBar : UINavigationBar { ...@@ -302,41 +319,38 @@ public class NavigationBar : UINavigationBar {
*/ */
internal func layoutNavigationItem(item: UINavigationItem) { internal func layoutNavigationItem(item: UINavigationItem) {
if willRenderView { if willRenderView {
if nil == item.titleView { prepareItem(item)
item.titleView = UIView(frame: CGRectZero)
}
if let titleView: UIView = item.titleView { if let titleView: UIView = prepareTitleView(item) {
titleView.frame.origin = CGPointZero if let contentView: UIView = prepareContentView(item) {
titleView.frame.size = intrinsicContentSize() let factor: CGFloat = 24
titleView.grid.axis.columns = Int(width / 48) if let grid: Int = Int(width / factor) {
let columns: Int = grid + 1
if nil == item.contentView {
item.contentView = UIView() titleView.frame.origin = CGPointZero
} titleView.frame.size = intrinsicContentSize()
if let contentView: UIView = item.contentView {
contentView.grid.columns = titleView.grid.axis.columns
// Size of single grid column.
if let g: CGFloat = width / CGFloat(0 < titleView.grid.axis.columns ? titleView.grid.axis.columns : 1) {
titleView.grid.views = [] titleView.grid.views = []
titleView.grid.axis.columns = columns
contentView.grid.columns = columns
// leftControls // leftControls
if let v: Array<UIControl> = item.leftControls { if let v: Array<UIControl> = item.leftControls {
for c in v { for c in v {
let w: CGFloat = c.intrinsicContentSize().width let w: CGFloat = c.intrinsicContentSize().width
if let b: UIButton = c as? UIButton { (c as? UIButton)?.contentEdgeInsets = UIEdgeInsetsZero
b.contentEdgeInsets = UIEdgeInsetsZero
}
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
let q: Int = Int(w / factor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
titleView.addSubview(c) titleView.addSubview(c)
titleView.grid.views?.append(c) titleView.grid.views?.append(c)
} }
} }
titleView.addSubview(contentView) titleView.addSubview(contentView)
titleView.grid.views?.append(contentView) titleView.grid.views?.append(contentView)
...@@ -344,57 +358,53 @@ public class NavigationBar : UINavigationBar { ...@@ -344,57 +358,53 @@ public class NavigationBar : UINavigationBar {
if let v: Array<UIControl> = item.rightControls { if let v: Array<UIControl> = item.rightControls {
for c in v { for c in v {
let w: CGFloat = c.intrinsicContentSize().width let w: CGFloat = c.intrinsicContentSize().width
if let b: UIButton = c as? UIButton { (c as? UIButton)?.contentEdgeInsets = UIEdgeInsetsZero
b.contentEdgeInsets = UIEdgeInsetsZero
}
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
let q: Int = Int(w / factor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
titleView.addSubview(c) titleView.addSubview(c)
titleView.grid.views?.append(c) titleView.grid.views?.append(c)
} }
} }
}
titleView.grid.contentInset = contentInset
contentView.grid.views = [] titleView.grid.spacing = spacing
titleView.grid.reloadLayout()
// contentView alignment.
if let title: String = item.title { // contentView alignment.
if let t: UILabel = item.titleLabel { if let titleLabel: UILabel = item.titleLabel {
if "" != title { if let _: String = titleLabel.text {
t.text = title if nil == titleLabel.superview {
} contentView.addSubview(titleLabel)
item.title = "" }
if "" != t.text {
t.grid.rows = 1
contentView.addSubview(t)
contentView.grid.views?.append(t)
if let detail: String = item.detail { if let detailLabel: UILabel = item.detailLabel {
if let d: UILabel = item.detailLabel { if let _: String = detailLabel.text {
t.font = t.font.fontWithSize(17) if nil == detailLabel.superview {
contentView.addSubview(detailLabel)
d.text = detail }
d.grid.rows = 1
d.font = d.font.fontWithSize(12)
contentView.addSubview(d) titleLabel.sizeToFit()
contentView.grid.axis.rows = 2 detailLabel.sizeToFit()
contentView.grid.views?.append(d) let diff: CGFloat = (contentView.frame.height - titleLabel.frame.height - detailLabel.frame.height) / 2
titleLabel.frame.size.height += diff
detailLabel.frame.size.height += diff
detailLabel.frame.origin.y = titleLabel.frame.height
} else {
detailLabel.removeFromSuperview()
titleLabel.frame = contentView.bounds
} }
} else {
t.font = t.font?.fontWithSize(20)
contentView.grid.axis.rows = 1
} }
} else {
titleLabel.removeFromSuperview()
contentView.grid.reloadLayout()
} }
} }
} }
titleView.grid.contentInset = contentInset
titleView.grid.spacing = spacing
titleView.grid.reloadLayout()
contentView.grid.axis.direction = .Vertical
contentView.grid.reloadLayout()
} }
} }
} }
...@@ -427,4 +437,26 @@ public class NavigationBar : UINavigationBar { ...@@ -427,4 +437,26 @@ public class NavigationBar : UINavigationBar {
shadowImage = image shadowImage = image
setBackgroundImage(image, forBarMetrics: .Default) setBackgroundImage(image, forBarMetrics: .Default)
} }
/// Prepares the item.
private func prepareItem(item: UINavigationItem) {
item.title = ""
}
/// Prepare the titleView.
private func prepareTitleView(item: UINavigationItem) -> UIView {
if nil == item.titleView {
item.titleView = UIView(frame: CGRectZero)
}
return item.titleView!
}
/// Prepare the contentView.
private func prepareContentView(item: UINavigationItem) -> UIView {
if nil == item.contentView {
item.contentView = UIView(frame: CGRectZero)
}
item.contentView!.grid.axis.direction = .Vertical
return item.contentView!
}
} }
...@@ -38,13 +38,13 @@ public class MaterialAssociatedObjectNavigationItem { ...@@ -38,13 +38,13 @@ public class MaterialAssociatedObjectNavigationItem {
public var contentView: UIView? public var contentView: UIView?
/// Title label. /// Title label.
public var titleLabel: UILabel public private(set) var titleLabel: UILabel!
/// Detail text. /// Detail text.
public var detail: String? public var detail: String?
/// Detail label. /// Detail label.
public var detailLabel: UILabel public private(set) var detailLabel: UILabel!
/// Left controls. /// Left controls.
public var leftControls: Array<UIControl>? public var leftControls: Array<UIControl>?
...@@ -52,9 +52,24 @@ public class MaterialAssociatedObjectNavigationItem { ...@@ -52,9 +52,24 @@ public class MaterialAssociatedObjectNavigationItem {
/// Right controls. /// Right controls.
public var rightControls: Array<UIControl>? public var rightControls: Array<UIControl>?
/// Initializer.
public init() { public init() {
prepareTitleLabel()
prepareDetailLabel()
}
/// Prepares the titleLabel.
private func prepareTitleLabel() {
titleLabel = UILabel() titleLabel = UILabel()
titleLabel.font = RobotoFont.mediumWithSize(17)
titleLabel.textAlignment = .Left
}
/// Prepares the detailLabel.
private func prepareDetailLabel() {
detailLabel = UILabel() detailLabel = UILabel()
detailLabel.font = RobotoFont.regularWithSize(12)
detailLabel.textAlignment = .Left
} }
} }
......
...@@ -74,7 +74,7 @@ public class StatusBarView : ControlView { ...@@ -74,7 +74,7 @@ public class StatusBarView : ControlView {
width = MaterialDevice.width width = MaterialDevice.width
} }
grid.axis.columns = Int(width / 48) grid.axis.columns = Int(width / 24)
// General alignment. // General alignment.
if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape { if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape {
......
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