Commit 26d17b93 by Daniel Dahan

reworked NavigationBar

parents 877c82dd 77143ea2
...@@ -98,12 +98,9 @@ class AppLeftViewController: UIViewController { ...@@ -98,12 +98,9 @@ class AppLeftViewController: UIViewController {
nameLabel.font = RobotoFont.mediumWithSize(18) nameLabel.font = RobotoFont.mediumWithSize(18)
view.addSubview(nameLabel) view.addSubview(nameLabel)
profileView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTopLeft(view, child: profileView, top: 30, left: (view.bounds.width - 72) / 2) MaterialLayout.alignFromTopLeft(view, child: profileView, top: 30, left: (view.bounds.width - 72) / 2)
MaterialLayout.size(view, child: profileView, width: 72, height: 72) MaterialLayout.size(view, child: profileView, width: 72, height: 72)
nameLabel.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: nameLabel, top: 130) MaterialLayout.alignFromTop(view, child: nameLabel, top: 130)
MaterialLayout.alignToParentHorizontally(view, child: nameLabel, left: 20, right: 20) MaterialLayout.alignToParentHorizontally(view, child: nameLabel, left: 20, right: 20)
} }
...@@ -118,7 +115,6 @@ class AppLeftViewController: UIViewController { ...@@ -118,7 +115,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, top: 170) MaterialLayout.alignToParent(view, child: tableView, top: 170)
} }
} }
......
...@@ -140,7 +140,6 @@ class AppMenuViewController: MenuViewController { ...@@ -140,7 +140,6 @@ class AppMenuViewController: MenuViewController {
menuView.menu.views = [menuButton, blueButton, greenButton, yellowButton] menuView.menu.views = [menuButton, blueButton, greenButton, yellowButton]
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)
} }
......
...@@ -33,31 +33,29 @@ import Material ...@@ -33,31 +33,29 @@ import Material
class AppNavigationController: NavigationController { class AppNavigationController: NavigationController {
/// StatusBar color reference. /// StatusBar color reference.
private var statusBarView: MaterialView? // private var statusBarView: MaterialView?
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareStatusBarView() // prepareStatusBarView()
prepareNavigationBar() prepareNavigationBar()
} }
override func viewWillLayoutSubviews() { override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
statusBarView?.hidden = MaterialDevice.statusBarHidden // statusBarView?.hidden = MaterialDevice.statusBarHidden
print(MaterialDevice.statusBarHidden)
} }
/// Prepares the statusBarView /// Prepares the statusBarView
private func prepareStatusBarView() { // private func prepareStatusBarView() {
statusBarView = MaterialView() // statusBarView = MaterialView()
statusBarView!.backgroundColor = MaterialColor.blue.darken2 // statusBarView!.backgroundColor = MaterialColor.blue.darken2
//
view.addSubview(statusBarView!) // view.addSubview(statusBarView!)
statusBarView!.translatesAutoresizingMaskIntoConstraints = false // MaterialLayout.alignFromTop(view, child: statusBarView!)
MaterialLayout.alignFromTop(view, child: statusBarView!) // MaterialLayout.alignToParentHorizontally(view, child: statusBarView!)
MaterialLayout.alignToParentHorizontally(view, child: statusBarView!) // MaterialLayout.height(view, child: statusBarView!, height: 20)
MaterialLayout.height(view, child: statusBarView!, height: 20) // }
}
/// Prepares the navigationBar /// Prepares the navigationBar
private func prepareNavigationBar() { private func prepareNavigationBar() {
......
...@@ -66,7 +66,6 @@ class ItemViewController: UIViewController { ...@@ -66,7 +66,6 @@ class ItemViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareTitleLabel()
prepareShareButton() prepareShareButton()
prepareNavigationItem() prepareNavigationItem()
prepareScrollView() prepareScrollView()
...@@ -79,6 +78,16 @@ class ItemViewController: UIViewController { ...@@ -79,6 +78,16 @@ class ItemViewController: UIViewController {
// Stops the scrollView contentInsets from being automatically adjusted. // Stops the scrollView contentInsets from being automatically adjusted.
automaticallyAdjustsScrollViewInsets = false automaticallyAdjustsScrollViewInsets = false
// Customize the navigationItem.backButton image here.
// (navigationController?.navigationBar as? NavigationBar)?.backButtonImage = MaterialIcon.cm.audioLibrary
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
// Access the navigationItem.backButton here.
// navigationItem.backButton
} }
override func viewWillLayoutSubviews() { override func viewWillLayoutSubviews() {
...@@ -101,22 +110,6 @@ class ItemViewController: UIViewController { ...@@ -101,22 +110,6 @@ class ItemViewController: UIViewController {
automaticallyAdjustsScrollViewInsets = false automaticallyAdjustsScrollViewInsets = false
} }
/// Prepares the titleLabel.
private func prepareTitleLabel() {
titleLabel = UILabel()
titleLabel.text = "Item"
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
}
/// Prepares the detailLabel.
private func prepareDetailLabel() {
detailLabel = UILabel()
detailLabel.text = "January 22, 2016"
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
}
/// Prepares the shareButton. /// Prepares the shareButton.
private func prepareShareButton() { private func prepareShareButton() {
let image: UIImage? = MaterialIcon.cm.share let image: UIImage? = MaterialIcon.cm.share
...@@ -128,8 +121,14 @@ class ItemViewController: UIViewController { ...@@ -128,8 +121,14 @@ class ItemViewController: UIViewController {
/// Prepares the navigationItem. /// Prepares the navigationItem.
private func prepareNavigationItem() { private func prepareNavigationItem() {
navigationItem.titleLabel = titleLabel navigationItem.titleLabel.text = "Item"
navigationItem.detailLabel = detailLabel navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.textColor = MaterialColor.white
navigationItem.detailLabel.text = "January 22, 2016"
navigationItem.detailLabel.textAlignment = .Left
navigationItem.detailLabel.textColor = MaterialColor.white
navigationItem.rightControls = [shareButton] navigationItem.rightControls = [shareButton]
} }
...@@ -156,16 +155,16 @@ class ItemViewController: UIViewController { ...@@ -156,16 +155,16 @@ class ItemViewController: UIViewController {
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.detailView = detailLabel imageCardView.contentView = detailLabel
imageCardView.detailViewInset.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
......
...@@ -54,7 +54,6 @@ class RecipesViewController: UIViewController { ...@@ -54,7 +54,6 @@ class RecipesViewController: UIViewController {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareItems() prepareItems()
prepareTitleLabel()
prepareMenuButton() prepareMenuButton()
prepareSwitchControl() prepareSwitchControl()
prepareSearchButton() prepareSearchButton()
...@@ -218,14 +217,6 @@ class RecipesViewController: UIViewController { ...@@ -218,14 +217,6 @@ class RecipesViewController: UIViewController {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
} }
/// Prepares the titleLabel.
private func prepareTitleLabel() {
titleLabel = UILabel()
titleLabel.text = "Recipes"
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
}
/// Prepares the menuButton. /// Prepares the menuButton.
private func prepareMenuButton() { private func prepareMenuButton() {
let image: UIImage? = MaterialIcon.cm.menu let image: UIImage? = MaterialIcon.cm.menu
...@@ -253,7 +244,10 @@ class RecipesViewController: UIViewController { ...@@ -253,7 +244,10 @@ class RecipesViewController: UIViewController {
/// Prepares the navigationItem. /// Prepares the navigationItem.
private func prepareNavigationItem() { private func prepareNavigationItem() {
navigationItem.titleLabel = titleLabel navigationItem.titleLabel.text = "Recipes"
navigationItem.titleLabel.textColor = MaterialColor.white
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
navigationItem.leftControls = [menuButton] navigationItem.leftControls = [menuButton]
navigationItem.rightControls = [switchControl, searchButton] navigationItem.rightControls = [switchControl, searchButton]
} }
...@@ -267,7 +261,6 @@ class RecipesViewController: UIViewController { ...@@ -267,7 +261,6 @@ class RecipesViewController: 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)
} }
} }
...@@ -314,7 +307,6 @@ extension RecipesViewController: UITableViewDataSource { ...@@ -314,7 +307,6 @@ extension RecipesViewController: UITableViewDataSource {
label.text = "Favorites" label.text = "Favorites"
header.addSubview(label) header.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(header, child: label, left: 24) MaterialLayout.alignToParent(header, child: label, left: 24)
return header return header
......
...@@ -71,7 +71,6 @@ class RecommendationViewController: UIViewController { ...@@ -71,7 +71,6 @@ class RecommendationViewController: 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)
} }
} }
...@@ -118,7 +117,6 @@ extension RecommendationViewController: UITableViewDataSource { ...@@ -118,7 +117,6 @@ extension RecommendationViewController: UITableViewDataSource {
label.text = "Recommendations" label.text = "Recommendations"
header.addSubview(label) header.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(header, child: label, left: 24) MaterialLayout.alignToParent(header, child: label, left: 24)
return header return header
......
...@@ -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)
......
...@@ -61,7 +61,7 @@ class ViewController: UIViewController { ...@@ -61,7 +61,7 @@ class ViewController: UIViewController {
let detailLabel: UILabel = UILabel() let detailLabel: UILabel = UILabel()
detailLabel.text = "It’s been a while, have you read any new books lately?" detailLabel.text = "It’s been a while, have you read any new books lately?"
detailLabel.numberOfLines = 0 detailLabel.numberOfLines = 0
cardView.detailView = detailLabel cardView.contentView = detailLabel
// Yes button. // Yes button.
let btn1: FlatButton = FlatButton() let btn1: FlatButton = FlatButton()
...@@ -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
...@@ -106,7 +104,7 @@ class ViewController: UIViewController { ...@@ -106,7 +104,7 @@ class ViewController: UIViewController {
detailLabel.text = "Beautiful Material Design" detailLabel.text = "Beautiful Material Design"
detailLabel.textColor = MaterialColor.white detailLabel.textColor = MaterialColor.white
detailLabel.numberOfLines = 0 detailLabel.numberOfLines = 0
cardView.detailView = detailLabel cardView.contentView = detailLabel
// Share button. // Share button.
let img1: UIImage? = MaterialIcon.cm.share let img1: UIImage? = MaterialIcon.cm.share
...@@ -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)
} }
...@@ -147,7 +144,7 @@ class ViewController: UIViewController { ...@@ -147,7 +144,7 @@ class ViewController: UIViewController {
detailLabel.text = "Data-Driven Framework" detailLabel.text = "Data-Driven Framework"
detailLabel.textColor = MaterialColor.white detailLabel.textColor = MaterialColor.white
detailLabel.numberOfLines = 0 detailLabel.numberOfLines = 0
cardView.detailView = detailLabel cardView.contentView = detailLabel
// Share button. // Share button.
let img1: UIImage? = MaterialIcon.cm.share let img1: UIImage? = MaterialIcon.cm.share
...@@ -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)
} }
......
...@@ -65,7 +65,7 @@ class ViewController: UIViewController { ...@@ -65,7 +65,7 @@ class ViewController: UIViewController {
let detailLabel: UILabel = UILabel() let detailLabel: UILabel = UILabel()
detailLabel.text = "It’s been a while, have you read any new books lately?" detailLabel.text = "It’s been a while, have you read any new books lately?"
detailLabel.numberOfLines = 0 detailLabel.numberOfLines = 0
imageCardView.detailView = detailLabel imageCardView.contentView = detailLabel
// Yes button. // Yes button.
let btn1: FlatButton = FlatButton() let btn1: FlatButton = FlatButton()
...@@ -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)
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
*/ */
/* /*
The following is an example of setting a UITableView as the detailView for a The following is an example of setting a UITableView as the contentView for a
CardView. CardView.
*/ */
...@@ -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)
} }
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
96F2F1F51C97A60800A5FE27 /* AppSearchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1EC1C97A60800A5FE27 /* AppSearchBarController.swift */; }; 96F2F1F51C97A60800A5FE27 /* AppSearchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1EC1C97A60800A5FE27 /* AppSearchBarController.swift */; };
96F2F1F61C97A60800A5FE27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1ED1C97A60800A5FE27 /* Assets.xcassets */; }; 96F2F1F61C97A60800A5FE27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1ED1C97A60800A5FE27 /* Assets.xcassets */; };
96F2F1F71C97A60800A5FE27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1EE1C97A60800A5FE27 /* LaunchScreen.storyboard */; }; 96F2F1F71C97A60800A5FE27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1EE1C97A60800A5FE27 /* LaunchScreen.storyboard */; };
96F2F1F81C97A60800A5FE27 /* BlueViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1F01C97A60800A5FE27 /* BlueViewController.swift */; };
96F2F1F91C97A60800A5FE27 /* GreenViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1F11C97A60800A5FE27 /* GreenViewController.swift */; };
96F2F1FB1C97A60800A5FE27 /* YellowViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1F31C97A60800A5FE27 /* YellowViewController.swift */; }; 96F2F1FB1C97A60800A5FE27 /* YellowViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1F31C97A60800A5FE27 /* YellowViewController.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -35,8 +33,6 @@ ...@@ -35,8 +33,6 @@
96F2F1EC1C97A60800A5FE27 /* AppSearchBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppSearchBarController.swift; sourceTree = "<group>"; }; 96F2F1EC1C97A60800A5FE27 /* AppSearchBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppSearchBarController.swift; sourceTree = "<group>"; };
96F2F1ED1C97A60800A5FE27 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 96F2F1ED1C97A60800A5FE27 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
96F2F1EF1C97A60800A5FE27 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 96F2F1EF1C97A60800A5FE27 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
96F2F1F01C97A60800A5FE27 /* BlueViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlueViewController.swift; sourceTree = "<group>"; };
96F2F1F11C97A60800A5FE27 /* GreenViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GreenViewController.swift; sourceTree = "<group>"; };
96F2F1F21C97A60800A5FE27 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 96F2F1F21C97A60800A5FE27 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
96F2F1F31C97A60800A5FE27 /* YellowViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YellowViewController.swift; sourceTree = "<group>"; }; 96F2F1F31C97A60800A5FE27 /* YellowViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YellowViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
...@@ -73,8 +69,6 @@ ...@@ -73,8 +69,6 @@
children = ( children = (
96F2F1EB1C97A60800A5FE27 /* AppDelegate.swift */, 96F2F1EB1C97A60800A5FE27 /* AppDelegate.swift */,
96F2F1EC1C97A60800A5FE27 /* AppSearchBarController.swift */, 96F2F1EC1C97A60800A5FE27 /* AppSearchBarController.swift */,
96F2F1F01C97A60800A5FE27 /* BlueViewController.swift */,
96F2F1F11C97A60800A5FE27 /* GreenViewController.swift */,
96F2F1F31C97A60800A5FE27 /* YellowViewController.swift */, 96F2F1F31C97A60800A5FE27 /* YellowViewController.swift */,
96F2F1ED1C97A60800A5FE27 /* Assets.xcassets */, 96F2F1ED1C97A60800A5FE27 /* Assets.xcassets */,
96F2F1EE1C97A60800A5FE27 /* LaunchScreen.storyboard */, 96F2F1EE1C97A60800A5FE27 /* LaunchScreen.storyboard */,
...@@ -154,9 +148,7 @@ ...@@ -154,9 +148,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
96F2F1F91C97A60800A5FE27 /* GreenViewController.swift in Sources */,
96F2F1F51C97A60800A5FE27 /* AppSearchBarController.swift in Sources */, 96F2F1F51C97A60800A5FE27 /* AppSearchBarController.swift in Sources */,
96F2F1F81C97A60800A5FE27 /* BlueViewController.swift in Sources */,
96F2F1F41C97A60800A5FE27 /* AppDelegate.swift in Sources */, 96F2F1F41C97A60800A5FE27 /* AppDelegate.swift in Sources */,
96F2F1FB1C97A60800A5FE27 /* YellowViewController.swift in Sources */, 96F2F1FB1C97A60800A5FE27 /* YellowViewController.swift in Sources */,
); );
......
...@@ -43,31 +43,6 @@ class AppSearchBarController: SearchBarController { ...@@ -43,31 +43,6 @@ class AppSearchBarController: SearchBarController {
prepareSearchBar() prepareSearchBar()
} }
/// Loads the BlueViewController into the searchBarControllers rootViewController.
func handleBlueButton() {
if rootViewController is BlueViewController {
return
}
transitionFromRootViewController(BlueViewController(), options: [.TransitionCrossDissolve])
}
/// Loads the GreenViewController into the searchBarControllers rootViewController.
func handleGreenButton() {
if rootViewController is GreenViewController {
return
}
transitionFromRootViewController(GreenViewController(), options: [.TransitionCrossDissolve])
}
/// Loads the YellowViewController into the searchBarControllers rootViewController.
func handleYellowButton() {
if (rootViewController as? ToolbarController)?.rootViewController is YellowViewController {
return
}
transitionFromRootViewController(YellowViewController(), options: [.TransitionCrossDissolve])
searchBar.textField.resignFirstResponder()
}
/// Prepares view. /// Prepares view.
override func prepareView() { override func prepareView() {
super.prepareView() super.prepareView()
...@@ -83,7 +58,6 @@ class AppSearchBarController: SearchBarController { ...@@ -83,7 +58,6 @@ class AppSearchBarController: SearchBarController {
backButton.tintColor = MaterialColor.blueGrey.darken4 backButton.tintColor = MaterialColor.blueGrey.darken4
backButton.setImage(image, forState: .Normal) backButton.setImage(image, forState: .Normal)
backButton.setImage(image, forState: .Highlighted) backButton.setImage(image, forState: .Highlighted)
backButton.addTarget(self, action: #selector(handleBlueButton), forControlEvents: .TouchUpInside)
// More button. // More button.
image = MaterialIcon.cm.moreHorizontal image = MaterialIcon.cm.moreHorizontal
...@@ -91,7 +65,6 @@ class AppSearchBarController: SearchBarController { ...@@ -91,7 +65,6 @@ class AppSearchBarController: SearchBarController {
moreButton.tintColor = MaterialColor.blueGrey.darken4 moreButton.tintColor = MaterialColor.blueGrey.darken4
moreButton.setImage(image, forState: .Normal) moreButton.setImage(image, forState: .Normal)
moreButton.setImage(image, forState: .Highlighted) moreButton.setImage(image, forState: .Highlighted)
moreButton.addTarget(self, action: #selector(handleGreenButton), forControlEvents: .TouchUpInside)
/* /*
To lighten the status bar - add the To lighten the status bar - add the
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of GraphKit nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
import Material
class BlueViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
}
/// Prepares view.
private func prepareView() {
view.backgroundColor = MaterialColor.blue.base
}
}
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of GraphKit nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
import Material
class GreenViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
}
/// Prepares view.
private func prepareView() {
view.backgroundColor = MaterialColor.green.base
}
}
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</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>
......
...@@ -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)
} }
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
*/ */
/* /*
The following is an example of setting a UITableView as the detailView for a The following is an example of setting a UITableView as the contentView for a
CardView. CardView.
*/ */
...@@ -84,14 +84,13 @@ class ViewController: UIViewController { ...@@ -84,14 +84,13 @@ 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
cardView.contentInsetPreset = .None cardView.contentInsetPreset = .None
cardView.leftButtonsInsetPreset = .Square2 cardView.leftButtonsInsetPreset = .Square2
cardView.rightButtonsInsetPreset = .Square2 cardView.rightButtonsInsetPreset = .Square2
cardView.detailViewInsetPreset = .None cardView.contentViewInsetPreset = .None
let titleLabel: UILabel = UILabel() let titleLabel: UILabel = UILabel()
titleLabel.font = RobotoFont.mediumWithSize(20) titleLabel.font = RobotoFont.mediumWithSize(20)
...@@ -113,11 +112,10 @@ class ViewController: UIViewController { ...@@ -113,11 +112,10 @@ class ViewController: UIViewController {
// Use MaterialLayout to easily align the tableView. // Use MaterialLayout to easily align the tableView.
cardView.titleLabel = titleLabel cardView.titleLabel = titleLabel
cardView.detailView = tableView cardView.contentView = tableView
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)
} }
......
...@@ -57,18 +57,12 @@ class ViewController: UIViewController { ...@@ -57,18 +57,12 @@ class ViewController: UIViewController {
toolbar = Toolbar() toolbar = Toolbar()
// Title label. // Title label.
let titleLabel: UILabel = UILabel() toolbar.titleLabel.text = "Material"
titleLabel.text = "Material" toolbar.titleLabel.textColor = MaterialColor.white
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regular
// Detail label. // Detail label.
let detailLabel: UILabel = UILabel() toolbar.detailLabel.text = "Build Beautiful Software"
detailLabel.text = "Build Beautiful Software" toolbar.detailLabel.textColor = MaterialColor.white
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regular
var image: UIImage? = MaterialIcon.cm.menu var image: UIImage? = MaterialIcon.cm.menu
...@@ -97,8 +91,6 @@ class ViewController: UIViewController { ...@@ -97,8 +91,6 @@ class ViewController: UIViewController {
*/ */
toolbar.statusBarStyle = .LightContent toolbar.statusBarStyle = .LightContent
toolbar.backgroundColor = MaterialColor.blue.base toolbar.backgroundColor = MaterialColor.blue.base
toolbar.titleLabel = titleLabel
toolbar.detailLabel = detailLabel
toolbar.leftControls = [menuButton] toolbar.leftControls = [menuButton]
toolbar.rightControls = [switchControl, searchButton] toolbar.rightControls = [switchControl, searchButton]
......
...@@ -7,12 +7,11 @@ ...@@ -7,12 +7,11 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
9692C92A1CE44C0C008C2766 /* GreenViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9692C9281CE44C0C008C2766 /* GreenViewController.swift */; };
96F2F1D61C97A55B00A5FE27 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1CD1C97A55B00A5FE27 /* AppDelegate.swift */; }; 96F2F1D61C97A55B00A5FE27 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1CD1C97A55B00A5FE27 /* AppDelegate.swift */; };
96F2F1D71C97A55B00A5FE27 /* AppToolbarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1CE1C97A55B00A5FE27 /* AppToolbarController.swift */; }; 96F2F1D71C97A55B00A5FE27 /* AppToolbarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1CE1C97A55B00A5FE27 /* AppToolbarController.swift */; };
96F2F1D81C97A55B00A5FE27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1CF1C97A55B00A5FE27 /* Assets.xcassets */; }; 96F2F1D81C97A55B00A5FE27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1CF1C97A55B00A5FE27 /* Assets.xcassets */; };
96F2F1D91C97A55B00A5FE27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1D01C97A55B00A5FE27 /* LaunchScreen.storyboard */; }; 96F2F1D91C97A55B00A5FE27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1D01C97A55B00A5FE27 /* LaunchScreen.storyboard */; };
96F2F1DA1C97A55B00A5FE27 /* BlueViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1D21C97A55B00A5FE27 /* BlueViewController.swift */; };
96F2F1DB1C97A55B00A5FE27 /* GreenViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1D31C97A55B00A5FE27 /* GreenViewController.swift */; };
96F2F1DD1C97A55B00A5FE27 /* YellowViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1D51C97A55B00A5FE27 /* YellowViewController.swift */; }; 96F2F1DD1C97A55B00A5FE27 /* YellowViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1D51C97A55B00A5FE27 /* YellowViewController.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -30,13 +29,12 @@ ...@@ -30,13 +29,12 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
9692C9281CE44C0C008C2766 /* GreenViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GreenViewController.swift; sourceTree = "<group>"; };
96A71FC01C765FDF00C0C4AE /* ToolbarController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ToolbarController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 96A71FC01C765FDF00C0C4AE /* ToolbarController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ToolbarController.app; sourceTree = BUILT_PRODUCTS_DIR; };
96F2F1CD1C97A55B00A5FE27 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 96F2F1CD1C97A55B00A5FE27 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
96F2F1CE1C97A55B00A5FE27 /* AppToolbarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppToolbarController.swift; sourceTree = "<group>"; }; 96F2F1CE1C97A55B00A5FE27 /* AppToolbarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppToolbarController.swift; sourceTree = "<group>"; };
96F2F1CF1C97A55B00A5FE27 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 96F2F1CF1C97A55B00A5FE27 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
96F2F1D11C97A55B00A5FE27 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 96F2F1D11C97A55B00A5FE27 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
96F2F1D21C97A55B00A5FE27 /* BlueViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlueViewController.swift; sourceTree = "<group>"; };
96F2F1D31C97A55B00A5FE27 /* GreenViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GreenViewController.swift; sourceTree = "<group>"; };
96F2F1D41C97A55B00A5FE27 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 96F2F1D41C97A55B00A5FE27 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
96F2F1D51C97A55B00A5FE27 /* YellowViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YellowViewController.swift; sourceTree = "<group>"; }; 96F2F1D51C97A55B00A5FE27 /* YellowViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YellowViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
...@@ -73,8 +71,7 @@ ...@@ -73,8 +71,7 @@
children = ( children = (
96F2F1CD1C97A55B00A5FE27 /* AppDelegate.swift */, 96F2F1CD1C97A55B00A5FE27 /* AppDelegate.swift */,
96F2F1CE1C97A55B00A5FE27 /* AppToolbarController.swift */, 96F2F1CE1C97A55B00A5FE27 /* AppToolbarController.swift */,
96F2F1D21C97A55B00A5FE27 /* BlueViewController.swift */, 9692C9281CE44C0C008C2766 /* GreenViewController.swift */,
96F2F1D31C97A55B00A5FE27 /* GreenViewController.swift */,
96F2F1D51C97A55B00A5FE27 /* YellowViewController.swift */, 96F2F1D51C97A55B00A5FE27 /* YellowViewController.swift */,
96F2F1CF1C97A55B00A5FE27 /* Assets.xcassets */, 96F2F1CF1C97A55B00A5FE27 /* Assets.xcassets */,
96F2F1D01C97A55B00A5FE27 /* LaunchScreen.storyboard */, 96F2F1D01C97A55B00A5FE27 /* LaunchScreen.storyboard */,
...@@ -154,11 +151,10 @@ ...@@ -154,11 +151,10 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
96F2F1DB1C97A55B00A5FE27 /* GreenViewController.swift in Sources */,
96F2F1D71C97A55B00A5FE27 /* AppToolbarController.swift in Sources */, 96F2F1D71C97A55B00A5FE27 /* AppToolbarController.swift in Sources */,
96F2F1DA1C97A55B00A5FE27 /* BlueViewController.swift in Sources */,
96F2F1D61C97A55B00A5FE27 /* AppDelegate.swift in Sources */, 96F2F1D61C97A55B00A5FE27 /* AppDelegate.swift in Sources */,
96F2F1DD1C97A55B00A5FE27 /* YellowViewController.swift in Sources */, 96F2F1DD1C97A55B00A5FE27 /* YellowViewController.swift in Sources */,
9692C92A1CE44C0C008C2766 /* GreenViewController.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
......
...@@ -59,14 +59,9 @@ class AppToolbarController: ToolbarController { ...@@ -59,14 +59,9 @@ class AppToolbarController: ToolbarController {
view.backgroundColor = MaterialColor.black view.backgroundColor = MaterialColor.black
} }
/// Toggle SideNavigationController left UIViewController.
internal func handleMenuButton() {
transitionFromRootViewController(GreenViewController(), options: [.TransitionCrossDissolve])
}
/// Toggle SideNavigationController right UIViewController. /// Toggle SideNavigationController right UIViewController.
internal func handleSearchButton() { internal func handleSearchButton() {
floatingViewController = BlueViewController() floatingViewController = GreenViewController()
MaterialAnimation.delay(1.5) { [weak self] in MaterialAnimation.delay(1.5) { [weak self] in
// Removes the ViewController from the view stack. // Removes the ViewController from the view stack.
...@@ -77,32 +72,28 @@ class AppToolbarController: ToolbarController { ...@@ -77,32 +72,28 @@ class AppToolbarController: ToolbarController {
/// Prepares the toolbar. /// Prepares the toolbar.
private func prepareToolbar() { private func prepareToolbar() {
// Title label. // Title label.
let titleLabel: UILabel = UILabel() toolbar.titleLabel.text = "Material"
titleLabel.text = "Material" toolbar.titleLabel.textAlignment = .Left
titleLabel.textAlignment = .Left toolbar.titleLabel.textColor = MaterialColor.white
titleLabel.textColor = MaterialColor.white toolbar.titleLabel.font = RobotoFont.regular
titleLabel.font = RobotoFont.regular
// Detail label. Uncomment the code below to use a detail label. // Detail label. Uncomment the code below to use a detail label.
// let detailLabel: UILabel = UILabel() // toolbar.detailLabel.text = "Build Beautiful Software"
// detailLabel.text = "Build Beautiful Software" // toolbar.detailLabel.textAlignment = .Left
// detailLabel.textAlignment = .Left // toolbar.detailLabel.textColor = MaterialColor.white
// detailLabel.textColor = MaterialColor.white // toolbar.detailLabel.font = RobotoFont.regular
// detailLabel.font = RobotoFont.regular
// toolbar.detailLabel = detailLabel
var image: UIImage? = MaterialIcon.cm.menu var image: UIImage? = MaterialIcon.cm.menu
// Menu button. // Menu button.
let menuButton: IconButton = IconButton() let menuButton: IconButton = IconButton()
menuButton.tintColor = MaterialColor.white menuButton.tintColor = MaterialColor.white
menuButton.pulseColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal) menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted) menuButton.setImage(image, forState: .Highlighted)
menuButton.addTarget(self, action: #selector(handleMenuButton), forControlEvents: .TouchUpInside)
// Switch control. // Switch control.
let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small) let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small)
switchControl.delegate = self
// Search button. // Search button.
image = MaterialIcon.cm.search image = MaterialIcon.cm.search
...@@ -112,16 +103,8 @@ class AppToolbarController: ToolbarController { ...@@ -112,16 +103,8 @@ class AppToolbarController: ToolbarController {
searchButton.setImage(image, forState: .Highlighted) searchButton.setImage(image, forState: .Highlighted)
searchButton.addTarget(self, action: #selector(handleSearchButton), forControlEvents: .TouchUpInside) searchButton.addTarget(self, action: #selector(handleSearchButton), forControlEvents: .TouchUpInside)
toolbar.backgroundColor = MaterialColor.blue.base
toolbar.titleLabel = titleLabel
toolbar.leftControls = [menuButton] toolbar.leftControls = [menuButton]
toolbar.rightControls = [switchControl, searchButton] toolbar.rightControls = [switchControl, searchButton]
toolbar.backgroundColor = MaterialColor.blue.base
} }
} }
extension AppToolbarController: MaterialSwitchDelegate {
func materialSwitchStateChanged(control: MaterialSwitch) {
transitionFromRootViewController(YellowViewController(), options: [.TransitionCrossDissolve])
}
}
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of GraphKit nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
import Material
class BlueViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
}
/// Prepares view.
private func prepareView() {
view.backgroundColor = MaterialColor.blue.base
}
}
...@@ -60,7 +60,7 @@ class ViewController: UIViewController { ...@@ -60,7 +60,7 @@ class ViewController: UIViewController {
let detailLabel: UILabel = UILabel() let detailLabel: UILabel = UILabel()
detailLabel.text = "It’s been a while, have you read any new books lately?" detailLabel.text = "It’s been a while, have you read any new books lately?"
detailLabel.numberOfLines = 0 detailLabel.numberOfLines = 0
topCardView.detailView = detailLabel topCardView.contentView = detailLabel
// Yes button. // Yes button.
let btn1: FlatButton = FlatButton() let btn1: FlatButton = FlatButton()
...@@ -91,7 +91,7 @@ class ViewController: UIViewController { ...@@ -91,7 +91,7 @@ class ViewController: UIViewController {
let detailLabel: UILabel = UILabel() let detailLabel: UILabel = UILabel()
detailLabel.text = "It’s been a while, have you read any new books lately?" detailLabel.text = "It’s been a while, have you read any new books lately?"
detailLabel.numberOfLines = 0 detailLabel.numberOfLines = 0
bottomCardView.detailView = detailLabel bottomCardView.contentView = detailLabel
// Yes button. // Yes button.
let btn1: FlatButton = FlatButton() let btn1: FlatButton = FlatButton()
......
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:NavigationController.xcodeproj">
</FileRef>
</Workspace>
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
{
"images" : [
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Material-Icon-29@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Material-Icon-29@3x.png",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Material-Icon-40@2x-1.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Material-Icon-40@3x.png",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Material-Icon-60@2x.png",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Material-Icon-60@3x.png",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Material-Icon-29.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Material-Icon-29@2x-1.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Material-Icon-40.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Material-Icon-40@2x.png",
"scale" : "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Material-Icon-76.png",
"scale" : "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Material-Icon-76@2x.png",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "Material-Icon-83.5@2x.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="3vT-XQ-F0b">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
<scene sceneID="VnK-O2-p3g">
<objects>
<navigationController id="3vT-XQ-F0b" customClass="NavigationController" customModule="Material" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="y1W-vf-i0D" customClass="NavigationBar" customModule="Material">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="backgroundColor">
<color key="value" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</navigationBar>
<connections>
<segue destination="1Pa-h7-2vi" kind="relationship" relationship="rootViewController" id="r6u-U1-TVx"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="AcS-D5-fxN" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-809" y="554"/>
</scene>
<!--View Controller-->
<scene sceneID="wfS-wQ-VBd">
<objects>
<viewController id="1Pa-h7-2vi" customClass="ViewController" customModule="NavigationController" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="to9-NS-pFA"/>
<viewControllerLayoutGuide type="bottom" id="Psm-NS-6bN"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="4I1-xf-zSj">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" id="Jew-05-VYd"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Ogd-7a-PgV" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-119" y="554"/>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
...@@ -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)
} }
......
...@@ -78,20 +78,12 @@ class ViewController: UIViewController { ...@@ -78,20 +78,12 @@ class ViewController: UIViewController {
toolbar.statusBarStyle = .LightContent toolbar.statusBarStyle = .LightContent
// Title label. // Title label.
let titleLabel: UILabel = UILabel() toolbar.titleLabel.text = "Material"
titleLabel.text = "Material" toolbar.titleLabel.textColor = MaterialColor.white
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regular
toolbar.titleLabel = titleLabel
// Detail label. // Detail label.
let detailLabel: UILabel = UILabel() toolbar.detailLabel.text = "Build Beautiful Software"
detailLabel.text = "Build Beautiful Software" toolbar.detailLabel.textColor = MaterialColor.white
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regular
toolbar.detailLabel = detailLabel
// Menu button. // Menu button.
let img1: UIImage? = MaterialIcon.cm.menu let img1: UIImage? = MaterialIcon.cm.menu
......
...@@ -233,7 +233,6 @@ public class BottomTabBar : UITabBar { ...@@ -233,7 +233,6 @@ public class BottomTabBar : UITabBar {
super.didMoveToSuperview() super.didMoveToSuperview()
if autoLayoutToSuperview { if autoLayoutToSuperview {
if let v: UIView = superview { if let v: UIView = superview {
translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromBottom(v, child: self) MaterialLayout.alignFromBottom(v, child: self)
MaterialLayout.alignToParentHorizontally(v, child: self) MaterialLayout.alignToParentHorizontally(v, child: self)
} }
......
...@@ -113,35 +113,33 @@ public class CardView : MaterialPulseView { ...@@ -113,35 +113,33 @@ public class CardView : MaterialPulseView {
*/ */
@IBInspectable public var titleLabel: UILabel? { @IBInspectable public var titleLabel: UILabel? {
didSet { didSet {
titleLabel?.translatesAutoresizingMaskIntoConstraints = false
reloadView() reloadView()
} }
} }
/** /**
:name: detailViewInsets :name: contentViewInsets
*/ */
public var detailViewInsetPreset: MaterialEdgeInset = .Square2 { public var contentViewInsetPreset: MaterialEdgeInset = .Square2 {
didSet { didSet {
detailViewInset = MaterialEdgeInsetToValue(detailViewInsetPreset) contentViewInset = MaterialEdgeInsetToValue(contentViewInsetPreset)
} }
} }
/** /**
:name: detailViewInset :name: contentViewInset
*/ */
@IBInspectable public var detailViewInset: UIEdgeInsets = MaterialEdgeInsetToValue(.Square2) { @IBInspectable public var contentViewInset: UIEdgeInsets = MaterialEdgeInsetToValue(.Square2) {
didSet { didSet {
reloadView() reloadView()
} }
} }
/** /**
:name: detailView :name: contentView
*/ */
@IBInspectable public var detailView: UIView? { @IBInspectable public var contentView: UIView? {
didSet { didSet {
detailView?.translatesAutoresizingMaskIntoConstraints = false
reloadView() reloadView()
} }
} }
...@@ -169,11 +167,6 @@ public class CardView : MaterialPulseView { ...@@ -169,11 +167,6 @@ public class CardView : MaterialPulseView {
*/ */
public var leftButtons: Array<UIButton>? { public var leftButtons: Array<UIButton>? {
didSet { didSet {
if let v = leftButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView() reloadView()
} }
} }
...@@ -201,11 +194,6 @@ public class CardView : MaterialPulseView { ...@@ -201,11 +194,6 @@ public class CardView : MaterialPulseView {
*/ */
public var rightButtons: Array<UIButton>? { public var rightButtons: Array<UIButton>? {
didSet { didSet {
if let v = rightButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView() reloadView()
} }
} }
...@@ -234,9 +222,9 @@ public class CardView : MaterialPulseView { ...@@ -234,9 +222,9 @@ public class CardView : MaterialPulseView {
/** /**
:name: init :name: init
*/ */
public convenience init?(image: UIImage? = nil, titleLabel: UILabel? = nil, detailView: UIView? = nil, leftButtons: Array<UIButton>? = nil, rightButtons: Array<UIButton>? = nil) { public convenience init?(image: UIImage? = nil, titleLabel: UILabel? = nil, contentView: UIView? = nil, leftButtons: Array<UIButton>? = nil, rightButtons: Array<UIButton>? = nil) {
self.init(frame: CGRectZero) self.init(frame: CGRectZero)
prepareProperties(image, titleLabel: titleLabel, detailView: detailView, leftButtons: leftButtons, rightButtons: rightButtons) prepareProperties(image, titleLabel: titleLabel, contentView: contentView, leftButtons: leftButtons, rightButtons: rightButtons)
} }
/** /**
...@@ -279,9 +267,9 @@ public class CardView : MaterialPulseView { ...@@ -279,9 +267,9 @@ public class CardView : MaterialPulseView {
if nil != titleLabel { if nil != titleLabel {
verticalFormat += "-(insetTop)" verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInset.top + titleLabelInset.top metrics["insetTop"] = contentInset.top + titleLabelInset.top
} else if nil != detailView { } else if nil != contentView {
verticalFormat += "-(insetTop)" verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInset.top + detailViewInset.top metrics["insetTop"] = contentInset.top + contentViewInset.top
} }
// title // title
...@@ -295,20 +283,20 @@ public class CardView : MaterialPulseView { ...@@ -295,20 +283,20 @@ public class CardView : MaterialPulseView {
} }
// detail // detail
if let v: UIView = detailView { if let v: UIView = contentView {
addSubview(v) addSubview(v)
if nil == titleLabel { if nil == titleLabel {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + detailViewInset.top metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentViewInset.top
} else { } else {
verticalFormat += "-(insetB)" verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInset.bottom + detailViewInset.top metrics["insetB"] = titleLabelInset.bottom + contentViewInset.top
} }
verticalFormat += "-[detailView]" verticalFormat += "-[contentView]"
views["detailView"] = v views["contentView"] = v
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInset.left + detailViewInset.left, right: contentInset.right + detailViewInset.right) MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInset.left + contentViewInset.left, right: contentInset.right + contentViewInset.right)
} }
// leftButtons // leftButtons
...@@ -382,11 +370,11 @@ public class CardView : MaterialPulseView { ...@@ -382,11 +370,11 @@ public class CardView : MaterialPulseView {
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
} }
if nil != detailView { if nil != contentView {
if nil == metrics["insetC"] { if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInset.bottom + detailViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0) metrics["insetBottom"] = contentInset.bottom + contentViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} else { } else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0) metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} }
} else if nil != titleLabel { } else if nil != titleLabel {
if nil == metrics["insetC"] { if nil == metrics["insetC"] {
...@@ -430,10 +418,10 @@ public class CardView : MaterialPulseView { ...@@ -430,10 +418,10 @@ public class CardView : MaterialPulseView {
/** /**
:name: prepareProperties :name: prepareProperties
*/ */
internal func prepareProperties(image: UIImage?, titleLabel: UILabel?, detailView: UIView?, leftButtons: Array<UIButton>?, rightButtons: Array<UIButton>?) { internal func prepareProperties(image: UIImage?, titleLabel: UILabel?, contentView: UIView?, leftButtons: Array<UIButton>?, rightButtons: Array<UIButton>?) {
self.image = image self.image = image
self.titleLabel = titleLabel self.titleLabel = titleLabel
self.detailView = detailView self.contentView = contentView
self.leftButtons = leftButtons self.leftButtons = leftButtons
self.rightButtons = rightButtons self.rightButtons = rightButtons
} }
......
...@@ -143,42 +143,56 @@ public class ControlView : MaterialView { ...@@ -143,42 +143,56 @@ public class ControlView : MaterialView {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { if willRenderView {
// Size of single grid column. let factor: CGFloat = 24
if let g: CGFloat = width / CGFloat(0 < grid.axis.columns ? grid.axis.columns : 1) { if let g: Int = Int(width / factor) {
let columns: Int = g + 1
frame.origin = CGPointZero
frame.size = intrinsicContentSize()
grid.views = [] grid.views = []
contentView.grid.views = [] grid.axis.columns = columns
contentView.grid.columns = grid.axis.columns
contentView.grid.columns = columns
// leftControls // leftControls
if let v: Array<UIControl> = leftControls { if let v: Array<UIControl> = 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 = frame.size.height - contentInset.top - contentInset.bottom
}
c.frame.size.height = height - contentInset.top - contentInset.bottom let q: Int = Int(w / factor)
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g)) c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c) grid.views?.append(c)
} }
} }
addSubview(contentView)
grid.views?.append(contentView) grid.views?.append(contentView)
// rightControls // rightControls
if let v: Array<UIControl> = rightControls { if let v: Array<UIControl> = 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 = frame.size.height - contentInset.top - contentInset.bottom
}
c.frame.size.height = height - contentInset.top - contentInset.bottom let q: Int = Int(w / factor)
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g)) c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c) grid.views?.append(c)
} }
} }
grid.contentInset = contentInset
grid.spacing = spacing
grid.reloadLayout() grid.reloadLayout()
} }
} }
...@@ -196,12 +210,6 @@ public class ControlView : MaterialView { ...@@ -196,12 +210,6 @@ public class ControlView : MaterialView {
prepareContentView() prepareContentView()
} }
/// Prepares the contentView.
public func prepareContentView() {
contentView.backgroundColor = nil
addSubview(contentView)
}
/** /**
Used to trigger property changes that initializers avoid. Used to trigger property changes that initializers avoid.
- Parameter leftControls: An Array of UIControls that go on the left side. - Parameter leftControls: An Array of UIControls that go on the left side.
...@@ -211,4 +219,10 @@ public class ControlView : MaterialView { ...@@ -211,4 +219,10 @@ public class ControlView : MaterialView {
self.leftControls = leftControls self.leftControls = leftControls
self.rightControls = rightControls self.rightControls = rightControls
} }
/// Prepares the contentView.
private func prepareContentView() {
contentView.backgroundColor = nil
addSubview(contentView)
}
} }
...@@ -206,35 +206,33 @@ public class ImageCardView : MaterialPulseView { ...@@ -206,35 +206,33 @@ public class ImageCardView : MaterialPulseView {
*/ */
@IBInspectable public var titleLabel: UILabel? { @IBInspectable public var titleLabel: UILabel? {
didSet { didSet {
titleLabel?.translatesAutoresizingMaskIntoConstraints = false
reloadView() reloadView()
} }
} }
/** /**
:name: detailViewInsets :name: contentViewInsets
*/ */
public var detailViewInsetPreset: MaterialEdgeInset = .Square2 { public var contentViewInsetPreset: MaterialEdgeInset = .Square2 {
didSet { didSet {
detailViewInset = MaterialEdgeInsetToValue(detailViewInsetPreset) contentViewInset = MaterialEdgeInsetToValue(contentViewInsetPreset)
} }
} }
/** /**
:name: detailViewInset :name: contentViewInset
*/ */
@IBInspectable public var detailViewInset: UIEdgeInsets = MaterialEdgeInsetToValue(.Square2) { @IBInspectable public var contentViewInset: UIEdgeInsets = MaterialEdgeInsetToValue(.Square2) {
didSet { didSet {
reloadView() reloadView()
} }
} }
/** /**
:name: detailView :name: contentView
*/ */
@IBInspectable public var detailView: UIView? { @IBInspectable public var contentView: UIView? {
didSet { didSet {
detailView?.translatesAutoresizingMaskIntoConstraints = false
reloadView() reloadView()
} }
} }
...@@ -262,11 +260,6 @@ public class ImageCardView : MaterialPulseView { ...@@ -262,11 +260,6 @@ public class ImageCardView : MaterialPulseView {
*/ */
public var leftButtons: Array<UIButton>? { public var leftButtons: Array<UIButton>? {
didSet { didSet {
if let v = leftButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView() reloadView()
} }
} }
...@@ -294,11 +287,6 @@ public class ImageCardView : MaterialPulseView { ...@@ -294,11 +287,6 @@ public class ImageCardView : MaterialPulseView {
*/ */
public var rightButtons: Array<UIButton>? { public var rightButtons: Array<UIButton>? {
didSet { didSet {
if let v = rightButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView() reloadView()
} }
} }
...@@ -327,9 +315,9 @@ public class ImageCardView : MaterialPulseView { ...@@ -327,9 +315,9 @@ public class ImageCardView : MaterialPulseView {
/** /**
:name: init :name: init
*/ */
public convenience init?(image: UIImage? = nil, titleLabel: UILabel? = nil, detailView: UIView? = nil, leftButtons: Array<UIButton>? = nil, rightButtons: Array<UIButton>? = nil) { public convenience init?(image: UIImage? = nil, titleLabel: UILabel? = nil, contentView: UIView? = nil, leftButtons: Array<UIButton>? = nil, rightButtons: Array<UIButton>? = nil) {
self.init(frame: CGRectZero) self.init(frame: CGRectZero)
prepareProperties(image, titleLabel: titleLabel, detailView: detailView, leftButtons: leftButtons, rightButtons: rightButtons) prepareProperties(image, titleLabel: titleLabel, contentView: contentView, leftButtons: leftButtons, rightButtons: rightButtons)
} }
/** /**
...@@ -379,9 +367,9 @@ public class ImageCardView : MaterialPulseView { ...@@ -379,9 +367,9 @@ public class ImageCardView : MaterialPulseView {
} else if nil != titleLabel { } else if nil != titleLabel {
verticalFormat += "-(insetTop)" verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInset.top + titleLabelInset.top metrics["insetTop"] = contentInset.top + titleLabelInset.top
} else if nil != detailView { } else if nil != contentView {
verticalFormat += "-(insetTop)" verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInset.top + detailViewInset.top metrics["insetTop"] = contentInset.top + contentViewInset.top
} }
// title // title
...@@ -398,20 +386,20 @@ public class ImageCardView : MaterialPulseView { ...@@ -398,20 +386,20 @@ public class ImageCardView : MaterialPulseView {
} }
// detail // detail
if let v: UIView = detailView { if let v: UIView = contentView {
addSubview(v) addSubview(v)
if nil == imageLayer?.contents && nil != titleLabel { if nil == imageLayer?.contents && nil != titleLabel {
verticalFormat += "-(insetB)" verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInset.bottom + detailViewInset.top metrics["insetB"] = titleLabelInset.bottom + contentViewInset.top
} else { } else {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + detailViewInset.top metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentViewInset.top
} }
verticalFormat += "-[detailView]" verticalFormat += "-[contentView]"
views["detailView"] = v views["contentView"] = v
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInset.left + detailViewInset.left, right: contentInset.right + detailViewInset.right) MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInset.left + contentViewInset.left, right: contentInset.right + contentViewInset.right)
} }
// leftButtons // leftButtons
...@@ -486,11 +474,11 @@ public class ImageCardView : MaterialPulseView { ...@@ -486,11 +474,11 @@ public class ImageCardView : MaterialPulseView {
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
} }
if nil != detailView { if nil != contentView {
if nil == metrics["insetC"] { if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInset.bottom + detailViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0) metrics["insetBottom"] = contentInset.bottom + contentViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} else { } else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0) metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} }
} else if nil != titleLabel { } else if nil != titleLabel {
if nil == metrics["insetC"] { if nil == metrics["insetC"] {
...@@ -501,7 +489,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -501,7 +489,7 @@ public class ImageCardView : MaterialPulseView {
} else if nil != metrics["insetC"] { } else if nil != metrics["insetC"] {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0) metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0)
} }
} else if nil != detailView { } else if nil != contentView {
if 0 < leftButtons?.count { if 0 < leftButtons?.count {
verticalFormat += "-(insetC)-[button]" verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0] views["button"] = leftButtons![0]
...@@ -515,9 +503,9 @@ public class ImageCardView : MaterialPulseView { ...@@ -515,9 +503,9 @@ public class ImageCardView : MaterialPulseView {
} }
if nil == metrics["insetC"] { if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInset.bottom + detailViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0) metrics["insetBottom"] = contentInset.bottom + contentViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} else { } else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0) metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} }
} else { } else {
if 0 < leftButtons?.count { if 0 < leftButtons?.count {
...@@ -583,10 +571,10 @@ public class ImageCardView : MaterialPulseView { ...@@ -583,10 +571,10 @@ public class ImageCardView : MaterialPulseView {
/** /**
:name: prepareProperties :name: prepareProperties
*/ */
internal func prepareProperties(image: UIImage?, titleLabel: UILabel?, detailView: UIView?, leftButtons: Array<UIButton>?, rightButtons: Array<UIButton>?) { internal func prepareProperties(image: UIImage?, titleLabel: UILabel?, contentView: UIView?, leftButtons: Array<UIButton>?, rightButtons: Array<UIButton>?) {
self.image = image self.image = image
self.titleLabel = titleLabel self.titleLabel = titleLabel
self.detailView = detailView self.contentView = contentView
self.leftButtons = leftButtons self.leftButtons = leftButtons
self.rightButtons = rightButtons self.rightButtons = rightButtons
} }
......
...@@ -349,6 +349,10 @@ public class MaterialButton : UIButton { ...@@ -349,6 +349,10 @@ public class MaterialButton : UIButton {
} }
} }
public override func alignmentRectInsets() -> UIEdgeInsets {
return UIEdgeInsetsZero
}
/** /**
A method that accepts CAAnimation objects and executes them on the A method that accepts CAAnimation objects and executes them on the
view's backing layer. view's backing layer.
......
...@@ -32,6 +32,46 @@ import UIKit ...@@ -32,6 +32,46 @@ import UIKit
@IBDesignable @IBDesignable
public class MaterialCollectionView : UICollectionView { public class MaterialCollectionView : UICollectionView {
/// A property that accesses the layer.frame.origin.x property.
@IBInspectable public var x: CGFloat {
get {
return layer.frame.origin.x
}
set(value) {
layer.frame.origin.x = value
}
}
/// A property that accesses the layer.frame.origin.y property.
@IBInspectable public var y: CGFloat {
get {
return layer.frame.origin.y
}
set(value) {
layer.frame.origin.y = value
}
}
/// A property that accesses the layer.frame.size.width property.
@IBInspectable public var width: CGFloat {
get {
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
}
}
/// A property that accesses the layer.frame.size.height property.
@IBInspectable public var height: CGFloat {
get {
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
}
}
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset { public var contentInsetPreset: MaterialEdgeInset {
get { get {
......
...@@ -31,35 +31,27 @@ ...@@ -31,35 +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]
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]
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 = []) {
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)-"
...@@ -75,9 +67,7 @@ public struct MaterialLayout { ...@@ -75,9 +67,7 @@ public struct MaterialLayout {
} }
} }
/** /// 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)-"
...@@ -93,92 +83,73 @@ public struct MaterialLayout { ...@@ -93,92 +83,73 @@ public struct MaterialLayout {
} }
} }
/** /// 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 = []) {
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 = []) {
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 = []) {
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 = []) {
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 = []) {
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 = []) {
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 = []) {
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 = []) {
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 = []) {
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 = []) {
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 = []) {
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,
......
...@@ -114,15 +114,21 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD ...@@ -114,15 +114,21 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
*/ */
public func navigationBar(navigationBar: UINavigationBar, shouldPushItem item: UINavigationItem) -> Bool { public func navigationBar(navigationBar: UINavigationBar, shouldPushItem item: UINavigationItem) -> Bool {
if let v: NavigationBar = navigationBar as? NavigationBar { if let v: NavigationBar = navigationBar as? NavigationBar {
item.setHidesBackButton(true, animated: false) let backButton: IconButton = IconButton()
backButton.pulseColor = MaterialColor.white
backButton.setImage(v.backButtonImage, forState: .Normal)
backButton.setImage(v.backButtonImage, forState: .Highlighted)
backButton.addTarget(self, action: #selector(handleBackButton), forControlEvents: .TouchUpInside)
if var c: Array<UIControl> = item.leftControls { if var c: Array<UIControl> = item.leftControls {
c.append(v.backButton) c.append(backButton)
item.leftControls = c item.leftControls = c
} else { } else {
item.leftControls = [v.backButton] item.leftControls = [backButton]
} }
v.backButton.removeTarget(self, action: #selector(handleBackButton), forControlEvents: .TouchUpInside)
v.backButton.addTarget(self, action: #selector(handleBackButton), forControlEvents: .TouchUpInside) item.backButton = backButton
item.hidesBackButton = true
v.layoutNavigationItem(item) v.layoutNavigationItem(item)
} }
return true return true
......
...@@ -34,20 +34,20 @@ import UIKit ...@@ -34,20 +34,20 @@ import UIKit
private var MaterialAssociatedObjectNavigationItemKey: UInt8 = 0 private var MaterialAssociatedObjectNavigationItemKey: UInt8 = 0
public class MaterialAssociatedObjectNavigationItem { public class MaterialAssociatedObjectNavigationItem {
/// Portrait inset. /// Back Button.
public var portraitInset: CGFloat public var backButton: IconButton?
/// Landscape inset. /// Content View.
public var landscapeInset: CGFloat public var contentView: UIView?
/// Detail View.
public var detailView: UIView?
/// Title label. /// Title label.
public var titleLabel: UILabel? public private(set) var titleLabel: UILabel!
/// Detail text.
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>?
...@@ -55,9 +55,24 @@ public class MaterialAssociatedObjectNavigationItem { ...@@ -55,9 +55,24 @@ public class MaterialAssociatedObjectNavigationItem {
/// Right controls. /// Right controls.
public var rightControls: Array<UIControl>? public var rightControls: Array<UIControl>?
public init(portraitInset: CGFloat, landscapeInset: CGFloat) { /// Initializer.
self.portraitInset = portraitInset public init() {
self.landscapeInset = landscapeInset prepareTitleLabel()
prepareDetailLabel()
}
/// Prepares the titleLabel.
private func prepareTitleLabel() {
titleLabel = UILabel()
titleLabel.font = RobotoFont.mediumWithSize(17)
titleLabel.textAlignment = .Left
}
/// Prepares the detailLabel.
private func prepareDetailLabel() {
detailLabel = UILabel()
detailLabel.font = RobotoFont.regularWithSize(12)
detailLabel.textAlignment = .Left
} }
} }
...@@ -66,7 +81,7 @@ public extension UINavigationItem { ...@@ -66,7 +81,7 @@ public extension UINavigationItem {
public internal(set) var item: MaterialAssociatedObjectNavigationItem { public internal(set) var item: MaterialAssociatedObjectNavigationItem {
get { get {
return MaterialAssociatedObject(self, key: &MaterialAssociatedObjectNavigationItemKey) { return MaterialAssociatedObject(self, key: &MaterialAssociatedObjectNavigationItemKey) {
return MaterialAssociatedObjectNavigationItem(portraitInset: .iPad == MaterialDevice.type || "iPhone 6s Plus" == MaterialDevice.model || "iPhone 6 Plus" == MaterialDevice.model ? -20 : -16, landscapeInset: -20) return MaterialAssociatedObjectNavigationItem()
} }
} }
set(value) { set(value) {
...@@ -74,48 +89,48 @@ public extension UINavigationItem { ...@@ -74,48 +89,48 @@ public extension UINavigationItem {
} }
} }
/// Portrait inset. /// Back Button.
public var portraitInset: CGFloat { public internal(set) var backButton: IconButton? {
get { get {
return item.portraitInset return item.backButton
} }
set(value) { set(value) {
item.portraitInset = value item.backButton = value
} }
} }
/// Landscape inset. /// Content View.
public var landscapeInset: CGFloat { public internal(set) var contentView: UIView? {
get { get {
return item.landscapeInset return item.contentView
} }
set(value) { set(value) {
item.landscapeInset = value item.contentView = value
} }
} }
/// Detail View. /// Title Label.
public var detailView: UIView? { public internal(set) var titleLabel: UILabel {
get { get {
return item.detailView return item.titleLabel
} }
set(value) { set(value) {
item.detailView = value item.titleLabel = value
} }
} }
/// Title Label. /// Detail text.
public var titleLabel: UILabel? { public var detail: String? {
get { get {
return item.titleLabel return item.detail
} }
set(value) { set(value) {
item.titleLabel = value item.detail = value
} }
} }
/// Detail Label. /// Detail Label.
public var detailLabel: UILabel? { public internal(set) var detailLabel: UILabel {
get { get {
return item.detailLabel return item.detailLabel
} }
......
...@@ -93,15 +93,20 @@ public class SearchBar : StatusBarView { ...@@ -93,15 +93,20 @@ public class SearchBar : StatusBarView {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { if willRenderView {
contentView.grid.views?.append(textField) textField.frame = contentView.bounds
contentView.grid.reloadLayout()
layoutClearButton() layoutClearButton()
} }
} }
/// Prepares the contentView. /**
public override func prepareContentView() { Prepares the view instance when intialized. When subclassing,
super.prepareContentView() it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public override func prepareView() {
super.prepareView()
prepareTextField() prepareTextField()
prepareClearButton() prepareClearButton()
} }
......
...@@ -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 / 56) grid.axis.columns = Int(width / 24)
// General alignment. // General alignment.
if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape { if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape {
......
...@@ -479,7 +479,6 @@ public class TextView: UITextView { ...@@ -479,7 +479,6 @@ public class TextView: UITextView {
/// prepares the placeholderLabel property. /// prepares the placeholderLabel property.
private func preparePlaceholderLabel() { private func preparePlaceholderLabel() {
if let v: UILabel = placeholderLabel { if let v: UILabel = placeholderLabel {
v.translatesAutoresizingMaskIntoConstraints = false
v.font = font v.font = font
v.textAlignment = textAlignment v.textAlignment = textAlignment
v.numberOfLines = 0 v.numberOfLines = 0
......
...@@ -32,91 +32,65 @@ import UIKit ...@@ -32,91 +32,65 @@ import UIKit
public class Toolbar : StatusBarView { public class Toolbar : StatusBarView {
/// Title label. /// Title label.
public var titleLabel: UILabel? { public private(set) var titleLabel: UILabel!
didSet {
if let v: UILabel = titleLabel {
contentView.addSubview(v)
}
layoutSubviews()
}
}
/// Detail label. /// Detail label.
public var detailLabel: UILabel? { public private(set) var detailLabel: UILabel!
didSet {
if let v: UILabel = detailLabel {
contentView.addSubview(v)
}
layoutSubviews()
}
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
/**
A convenience initializer with parameter settings.
- Parameter titleLabel: UILabel for the title.
- Parameter detailLabel: UILabel for the details.
- Parameter leftControls: An Array of UIControls that go on the left side.
- Parameter rightControls: An Array of UIControls that go on the right side.
*/
public init(titleLabel: UILabel? = nil, detailLabel: UILabel? = nil, leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) {
super.init(frame: CGRectZero)
prepareProperties(titleLabel, detailLabel: detailLabel, leftControls: leftControls, rightControls: rightControls)
}
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { if willRenderView {
if let _: String = titleLabel.text {
contentView.grid.views = [] if nil == titleLabel.superview {
contentView.addSubview(titleLabel)
// TitleView alignment. }
if let t: UILabel = titleLabel {
t.grid.rows = 1
contentView.grid.views?.append(t)
if let d: UILabel = detailLabel { if let _: String = detailLabel.text {
t.font = t.font.fontWithSize(17) if nil == detailLabel.superview {
contentView.addSubview(detailLabel)
d.grid.rows = 1 }
d.font = d.font.fontWithSize(12)
contentView.grid.axis.rows = 2 titleLabel.sizeToFit()
contentView.grid.views?.append(d) detailLabel.sizeToFit()
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 { } else {
t.font = t.font?.fontWithSize(20) detailLabel.removeFromSuperview()
contentView.grid.axis.rows = 1 titleLabel.frame = contentView.bounds
} }
} else {
titleLabel.removeFromSuperview()
contentView.grid.reloadLayout()
} }
grid.reloadLayout()
contentView.grid.reloadLayout()
} }
} }
/// Prepares the contentView.
public override func prepareContentView() {
super.prepareContentView()
contentView.grid.axis.direction = .Vertical
}
/** /**
Used to trigger property changes that initializers avoid. Prepares the view instance when intialized. When subclassing,
- Parameter titleLabel: UILabel for the title. it is recommended to override the prepareView method
- Parameter detailLabel: UILabel for the details. to initialize property values and other setup operations.
- Parameter leftControls: An Array of UIControls that go on the left side. The super.prepareView method should always be called immediately
- Parameter rightControls: An Array of UIControls that go on the right side. when subclassing.
*/ */
internal func prepareProperties(titleLabel: UILabel?, detailLabel: UILabel?, leftControls: Array<UIControl>?, rightControls: Array<UIControl>?) { public override func prepareView() {
prepareProperties(leftControls, rightControls: rightControls) super.prepareView()
self.titleLabel = titleLabel prepareTitleLabel()
self.detailLabel = detailLabel prepareDetailLabel()
}
/// Prepares the titleLabel.
private func prepareTitleLabel() {
titleLabel = UILabel()
titleLabel.font = RobotoFont.mediumWithSize(17)
titleLabel.textAlignment = .Left
}
/// Prepares the detailLabel.
private func prepareDetailLabel() {
detailLabel = UILabel()
detailLabel.font = RobotoFont.regularWithSize(12)
detailLabel.textAlignment = .Left
} }
} }
\ No newline at end of file
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