Commit 26d17b93 by Daniel Dahan

reworked NavigationBar

parents 877c82dd 77143ea2
......@@ -98,12 +98,9 @@ class AppLeftViewController: UIViewController {
nameLabel.font = RobotoFont.mediumWithSize(18)
view.addSubview(nameLabel)
profileView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTopLeft(view, child: profileView, top: 30, left: (view.bounds.width - 72) / 2)
MaterialLayout.size(view, child: profileView, width: 72, height: 72)
nameLabel.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: nameLabel, top: 130)
MaterialLayout.alignToParentHorizontally(view, child: nameLabel, left: 20, right: 20)
}
......@@ -118,7 +115,6 @@ class AppLeftViewController: UIViewController {
// Use MaterialLayout to easily align the tableView.
view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: tableView, top: 170)
}
}
......
......@@ -140,7 +140,6 @@ class AppMenuViewController: MenuViewController {
menuView.menu.views = [menuButton, blueButton, greenButton, yellowButton]
view.addSubview(menuView)
menuView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.size(view, child: menuView, width: baseViewSize.width, height: baseViewSize.height)
MaterialLayout.alignFromBottomRight(view, child: menuView, bottom: menuViewInset, right: menuViewInset)
}
......
......@@ -33,31 +33,29 @@ import Material
class AppNavigationController: NavigationController {
/// StatusBar color reference.
private var statusBarView: MaterialView?
// private var statusBarView: MaterialView?
override func viewDidLoad() {
super.viewDidLoad()
prepareStatusBarView()
// prepareStatusBarView()
prepareNavigationBar()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
statusBarView?.hidden = MaterialDevice.statusBarHidden
print(MaterialDevice.statusBarHidden)
// statusBarView?.hidden = MaterialDevice.statusBarHidden
}
/// Prepares the statusBarView
private func prepareStatusBarView() {
statusBarView = MaterialView()
statusBarView!.backgroundColor = MaterialColor.blue.darken2
view.addSubview(statusBarView!)
statusBarView!.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: statusBarView!)
MaterialLayout.alignToParentHorizontally(view, child: statusBarView!)
MaterialLayout.height(view, child: statusBarView!, height: 20)
}
// private func prepareStatusBarView() {
// statusBarView = MaterialView()
// statusBarView!.backgroundColor = MaterialColor.blue.darken2
//
// view.addSubview(statusBarView!)
// MaterialLayout.alignFromTop(view, child: statusBarView!)
// MaterialLayout.alignToParentHorizontally(view, child: statusBarView!)
// MaterialLayout.height(view, child: statusBarView!, height: 20)
// }
/// Prepares the navigationBar
private func prepareNavigationBar() {
......
......@@ -66,7 +66,6 @@ class ItemViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareTitleLabel()
prepareShareButton()
prepareNavigationItem()
prepareScrollView()
......@@ -79,6 +78,16 @@ class ItemViewController: UIViewController {
// Stops the scrollView contentInsets from being automatically adjusted.
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() {
......@@ -101,22 +110,6 @@ class ItemViewController: UIViewController {
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.
private func prepareShareButton() {
let image: UIImage? = MaterialIcon.cm.share
......@@ -128,8 +121,14 @@ class ItemViewController: UIViewController {
/// Prepares the navigationItem.
private func prepareNavigationItem() {
navigationItem.titleLabel = titleLabel
navigationItem.detailLabel = detailLabel
navigationItem.titleLabel.text = "Item"
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]
}
......@@ -156,16 +155,16 @@ class ItemViewController: UIViewController {
imageCardView.titleLabel?.text = data["title"] as? String
imageCardView.titleLabel?.textColor = MaterialColor.grey.darken4
imageCardView.titleLabel?.font = RobotoFont.regularWithSize(20)
let detailLabel: UILabel = UILabel()
detailLabel.text = data["detail"] as? String
detailLabel.textColor = MaterialColor.grey.darken2
detailLabel.font = RobotoFont.regular
detailLabel.numberOfLines = 0
imageCardView.detailView = detailLabel
imageCardView.detailViewInset.top = 52
imageCardView.contentView = detailLabel
imageCardView.contentViewInset.top = 52
let image: UIImage? = UIImage(named: data["image"] as! String)
imageCardView.image = image
......
......@@ -54,7 +54,6 @@ class RecipesViewController: UIViewController {
super.viewDidLoad()
prepareView()
prepareItems()
prepareTitleLabel()
prepareMenuButton()
prepareSwitchControl()
prepareSearchButton()
......@@ -218,14 +217,6 @@ class RecipesViewController: UIViewController {
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.
private func prepareMenuButton() {
let image: UIImage? = MaterialIcon.cm.menu
......@@ -253,7 +244,10 @@ class RecipesViewController: UIViewController {
/// Prepares the navigationItem.
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.rightControls = [switchControl, searchButton]
}
......@@ -267,7 +261,6 @@ class RecipesViewController: UIViewController {
// Use MaterialLayout to easily align the tableView.
view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: tableView)
}
}
......@@ -314,7 +307,6 @@ extension RecipesViewController: UITableViewDataSource {
label.text = "Favorites"
header.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(header, child: label, left: 24)
return header
......
......@@ -71,7 +71,6 @@ class RecommendationViewController: UIViewController {
// Use MaterialLayout to easily align the tableView.
view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: tableView)
}
}
......@@ -118,7 +117,6 @@ extension RecommendationViewController: UITableViewDataSource {
label.text = "Recommendations"
header.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(header, child: label, left: 24)
return header
......
......@@ -224,7 +224,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
view.addSubview(captureView)
captureView.tapToFocusEnabled = true
captureView.tapToExposeEnabled = true
captureView.translatesAutoresizingMaskIntoConstraints = false
captureView.delegate = self
captureView.captureSession.delegate = self
MaterialLayout.alignToParent(view, child: captureView)
......@@ -283,7 +282,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
let img4: UIImage? = UIImage(named: "ic_photo_camera_white_36pt")
cameraButton.width = 72
cameraButton.height = 72
cameraButton.pulseColor = nil
cameraButton.setImage(img4, forState: .Normal)
cameraButton.setImage(img4, forState: .Highlighted)
......@@ -297,7 +295,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
let img5: UIImage? = UIImage(named: "ic_videocam_white_36pt")
videoButton.width = 72
videoButton.height = 72
videoButton.pulseColor = nil
videoButton.setImage(img5, forState: .Normal)
videoButton.setImage(img5, forState: .Highlighted)
......@@ -309,7 +306,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
*/
private func prepareSwitchCamerasButton() {
let img: UIImage? = UIImage(named: "ic_camera_front_white")
switchCamerasButton.pulseColor = nil
switchCamerasButton.setImage(img, forState: .Normal)
switchCamerasButton.setImage(img, forState: .Highlighted)
......@@ -321,7 +317,6 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
*/
private func prepareFlashButton() {
let img: UIImage? = UIImage(named: "ic_flash_auto_white")
flashButton.pulseColor = nil
flashButton.setImage(img, forState: .Normal)
flashButton.setImage(img, forState: .Highlighted)
......
......@@ -61,7 +61,7 @@ class ViewController: UIViewController {
let detailLabel: UILabel = UILabel()
detailLabel.text = "It’s been a while, have you read any new books lately?"
detailLabel.numberOfLines = 0
cardView.detailView = detailLabel
cardView.contentView = detailLabel
// Yes button.
let btn1: FlatButton = FlatButton()
......@@ -80,7 +80,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout.
view.addSubview(cardView)
cardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: cardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
}
......@@ -89,7 +88,6 @@ class ViewController: UIViewController {
let cardView: CardView = CardView()
cardView.divider = false
cardView.backgroundColor = MaterialColor.red.base
cardView.pulseColor = nil
cardView.image = UIImage(named: "Material-iTunesArtWork")?.resize(toHeight: 75)
cardView.contentsGravityPreset = .BottomRight
......@@ -106,7 +104,7 @@ class ViewController: UIViewController {
detailLabel.text = "Beautiful Material Design"
detailLabel.textColor = MaterialColor.white
detailLabel.numberOfLines = 0
cardView.detailView = detailLabel
cardView.contentView = detailLabel
// Share button.
let img1: UIImage? = MaterialIcon.cm.share
......@@ -121,7 +119,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout.
view.addSubview(cardView)
cardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: cardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
}
......@@ -147,7 +144,7 @@ class ViewController: UIViewController {
detailLabel.text = "Data-Driven Framework"
detailLabel.textColor = MaterialColor.white
detailLabel.numberOfLines = 0
cardView.detailView = detailLabel
cardView.contentView = detailLabel
// Share button.
let img1: UIImage? = MaterialIcon.cm.share
......@@ -162,7 +159,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout.
view.addSubview(cardView)
cardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: cardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
}
......@@ -170,7 +166,6 @@ class ViewController: UIViewController {
private func prepareCardViewButtonBarExample() {
let cardView: CardView = CardView()
cardView.divider = false
cardView.pulseColor = nil
cardView.backgroundColor = MaterialColor.blueGrey.darken4
// Search button.
......@@ -203,7 +198,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout.
view.addSubview(cardView)
cardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: cardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
}
......
......@@ -65,7 +65,7 @@ class ViewController: UIViewController {
let detailLabel: UILabel = UILabel()
detailLabel.text = "It’s been a while, have you read any new books lately?"
detailLabel.numberOfLines = 0
imageCardView.detailView = detailLabel
imageCardView.contentView = detailLabel
// Yes button.
let btn1: FlatButton = FlatButton()
......@@ -84,7 +84,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout.
view.addSubview(imageCardView)
imageCardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: imageCardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: imageCardView, left: 20, right: 20)
}
......@@ -134,7 +133,6 @@ class ViewController: UIViewController {
// To support orientation changes, use MaterialLayout.
view.addSubview(imageCardView)
imageCardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: imageCardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: imageCardView, left: 20, right: 20)
}
......
......@@ -87,7 +87,6 @@ class ViewController: UIViewController {
// Use MaterialLayout to easily align the tableView.
view.addSubview(collectionView)
collectionView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: collectionView)
}
}
......
......@@ -46,27 +46,22 @@ class ViewController: UIViewController {
/// Prepares the MaterialDepth.
private func prepareMaterialDepth() {
let v1: MaterialView = MaterialView()
v1.translatesAutoresizingMaskIntoConstraints = false
v1.depth = .Depth1
view.addSubview(v1)
let v2: MaterialView = MaterialView()
v2.translatesAutoresizingMaskIntoConstraints = false
v2.depth = .Depth2
view.addSubview(v2)
let v3: MaterialView = MaterialView()
v3.translatesAutoresizingMaskIntoConstraints = false
v3.depth = .Depth3
view.addSubview(v3)
let v4: MaterialView = MaterialView()
v4.translatesAutoresizingMaskIntoConstraints = false
v4.depth = .Depth4
view.addSubview(v4)
let v5: MaterialView = MaterialView()
v5.translatesAutoresizingMaskIntoConstraints = false
v5.depth = .Depth5
view.addSubview(v5)
......
......@@ -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.
*/
......@@ -109,7 +109,6 @@ class ViewController: UIViewController {
tableView.registerClass(MaterialTableViewCell.self, forCellReuseIdentifier: "Cell")
tableView.dataSource = self
tableView.delegate = self
tableView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(tableView)
......
......@@ -53,28 +53,24 @@ class ViewController: UIViewController {
/// Layout views horizontally with equal width.
private func prepareAlignToParentHorizontallyExample() {
let label1: UILabel = UILabel()
label1.translatesAutoresizingMaskIntoConstraints = false
label1.backgroundColor = MaterialColor.red.base
label1.text = "A"
label1.textAlignment = .Center
view.addSubview(label1)
let label2: UILabel = UILabel()
label2.translatesAutoresizingMaskIntoConstraints = false
label2.backgroundColor = MaterialColor.green.base
label2.text = "B"
label2.textAlignment = .Center
view.addSubview(label2)
let label3: UILabel = UILabel()
label3.translatesAutoresizingMaskIntoConstraints = false
label3.backgroundColor = MaterialColor.blue.base
label3.text = "C"
label3.textAlignment = .Center
view.addSubview(label3)
let label4: UILabel = UILabel()
label4.translatesAutoresizingMaskIntoConstraints = false
label4.backgroundColor = MaterialColor.yellow.base
label4.text = "D"
label4.textAlignment = .Center
......@@ -103,28 +99,24 @@ class ViewController: UIViewController {
/// Layout views vertically with equal height.
private func prepareAlignToParentVerticallyExample() {
let label1: UILabel = UILabel()
label1.translatesAutoresizingMaskIntoConstraints = false
label1.backgroundColor = MaterialColor.red.base
label1.text = "A"
label1.textAlignment = .Center
view.addSubview(label1)
let label2: UILabel = UILabel()
label2.translatesAutoresizingMaskIntoConstraints = false
label2.backgroundColor = MaterialColor.green.base
label2.text = "B"
label2.textAlignment = .Center
view.addSubview(label2)
let label3: UILabel = UILabel()
label3.translatesAutoresizingMaskIntoConstraints = false
label3.backgroundColor = MaterialColor.blue.base
label3.text = "C"
label3.textAlignment = .Center
view.addSubview(label3)
let label4: UILabel = UILabel()
label4.translatesAutoresizingMaskIntoConstraints = false
label4.backgroundColor = MaterialColor.yellow.base
label4.text = "D"
label4.textAlignment = .Center
......
......@@ -51,10 +51,8 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
view.backgroundColor = MaterialColor.white
view.addSubview(topView)
topView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bottomView)
bottomView.translatesAutoresizingMaskIntoConstraints = false
bottomView.backgroundColor = MaterialColor.grey.darken4
MaterialLayout.alignToParentHorizontally(view, child: topView)
......@@ -66,18 +64,15 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
private func prepareLightContentMaterialSwitch() {
let c1: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small)
c1.delegate = self
c1.translatesAutoresizingMaskIntoConstraints = false
topView.addSubview(c1)
let c2: MaterialSwitch = MaterialSwitch(state: .On, style: .LightContent)
c2.delegate = self
c2.translatesAutoresizingMaskIntoConstraints = false
topView.addSubview(c2)
let c3: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Large)
c3.delegate = self
c3.enabled = false
c3.translatesAutoresizingMaskIntoConstraints = false
topView.addSubview(c3)
MaterialLayout.alignToParentHorizontally(topView, child: c1)
......@@ -90,18 +85,15 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
private func prepareDefaultMaterialSwitch() {
let c1: MaterialSwitch = MaterialSwitch(state: .Off, style: .Default, size: .Small)
c1.delegate = self
c1.translatesAutoresizingMaskIntoConstraints = false
bottomView.addSubview(c1)
let c2: MaterialSwitch = MaterialSwitch(state: .On)
c2.delegate = self
c2.translatesAutoresizingMaskIntoConstraints = false
bottomView.addSubview(c2)
let c3: MaterialSwitch = MaterialSwitch(state: .Off, style: .Default, size: .Large)
c3.delegate = self
c3.enabled = false
c3.translatesAutoresizingMaskIntoConstraints = false
bottomView.addSubview(c3)
MaterialLayout.alignToParentHorizontally(bottomView, child: c1)
......
......@@ -128,7 +128,6 @@ class ViewController: UIViewController {
private func prepareFabMenuExample() {
var image: UIImage? = UIImage(named: "ic_add_white")
let btn1: FabButton = FabButton()
btn1.pulseColor = nil
btn1.setImage(image, forState: .Normal)
btn1.setImage(image, forState: .Highlighted)
btn1.addTarget(self, action: #selector(handleFabMenu), forControlEvents: .TouchUpInside)
......
......@@ -85,7 +85,6 @@ class ViewController: UIViewController {
let btn1: FabButton = FabButton()
btn1.depth = .None
btn1.tintColor = MaterialColor.blue.accent3
btn1.pulseColor = nil
btn1.borderColor = MaterialColor.blue.accent3
btn1.backgroundColor = MaterialColor.white
btn1.borderWidth = 1
......@@ -139,7 +138,6 @@ class ViewController: UIViewController {
menuView.menu.views = [btn1, btn2, btn3, btn4]
view.addSubview(menuView)
menuView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.size(view, child: menuView, width: diameter, height: diameter)
MaterialLayout.alignFromBottomLeft(view, child: menuView, bottom: 16, left: (view.bounds.width - diameter) / 2)
}
......
......@@ -136,7 +136,6 @@ class AppMenuViewController: MenuViewController {
menuView.menu.views = [btn1, btn2, btn3, btn4]
view.addSubview(menuView)
menuView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.size(view, child: menuView, width: baseViewSize.width, height: baseViewSize.height)
MaterialLayout.alignFromBottomRight(view, child: menuView, bottom: menuViewInset, right: menuViewInset)
}
......
......@@ -11,8 +11,6 @@
96F2F1F51C97A60800A5FE27 /* AppSearchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1EC1C97A60800A5FE27 /* AppSearchBarController.swift */; };
96F2F1F61C97A60800A5FE27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1ED1C97A60800A5FE27 /* Assets.xcassets */; };
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 */; };
/* End PBXBuildFile section */
......@@ -35,8 +33,6 @@
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>"; };
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>"; };
96F2F1F31C97A60800A5FE27 /* YellowViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YellowViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -73,8 +69,6 @@
children = (
96F2F1EB1C97A60800A5FE27 /* AppDelegate.swift */,
96F2F1EC1C97A60800A5FE27 /* AppSearchBarController.swift */,
96F2F1F01C97A60800A5FE27 /* BlueViewController.swift */,
96F2F1F11C97A60800A5FE27 /* GreenViewController.swift */,
96F2F1F31C97A60800A5FE27 /* YellowViewController.swift */,
96F2F1ED1C97A60800A5FE27 /* Assets.xcassets */,
96F2F1EE1C97A60800A5FE27 /* LaunchScreen.storyboard */,
......@@ -154,9 +148,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
96F2F1F91C97A60800A5FE27 /* GreenViewController.swift in Sources */,
96F2F1F51C97A60800A5FE27 /* AppSearchBarController.swift in Sources */,
96F2F1F81C97A60800A5FE27 /* BlueViewController.swift in Sources */,
96F2F1F41C97A60800A5FE27 /* AppDelegate.swift in Sources */,
96F2F1FB1C97A60800A5FE27 /* YellowViewController.swift in Sources */,
);
......
......@@ -43,31 +43,6 @@ class AppSearchBarController: SearchBarController {
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.
override func prepareView() {
super.prepareView()
......@@ -83,7 +58,6 @@ class AppSearchBarController: SearchBarController {
backButton.tintColor = MaterialColor.blueGrey.darken4
backButton.setImage(image, forState: .Normal)
backButton.setImage(image, forState: .Highlighted)
backButton.addTarget(self, action: #selector(handleBlueButton), forControlEvents: .TouchUpInside)
// More button.
image = MaterialIcon.cm.moreHorizontal
......@@ -91,7 +65,6 @@ class AppSearchBarController: SearchBarController {
moreButton.tintColor = MaterialColor.blueGrey.darken4
moreButton.setImage(image, forState: .Normal)
moreButton.setImage(image, forState: .Highlighted)
moreButton.addTarget(self, action: #selector(handleGreenButton), forControlEvents: .TouchUpInside)
/*
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 @@
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
......
......@@ -76,7 +76,6 @@ class AppLeftViewController: UIViewController {
// Use MaterialLayout to easily align the tableView.
view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: tableView)
}
}
......
......@@ -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.
*/
......@@ -84,14 +84,13 @@ class ViewController: UIViewController {
/// Prepares the CardView.
func prepareCardView() {
let cardView: CardView = CardView()
cardView.pulseColor = nil
cardView.backgroundColor = MaterialColor.grey.lighten5
cardView.cornerRadiusPreset = .Radius1
cardView.divider = false
cardView.contentInsetPreset = .None
cardView.leftButtonsInsetPreset = .Square2
cardView.rightButtonsInsetPreset = .Square2
cardView.detailViewInsetPreset = .None
cardView.contentViewInsetPreset = .None
let titleLabel: UILabel = UILabel()
titleLabel.font = RobotoFont.mediumWithSize(20)
......@@ -113,11 +112,10 @@ class ViewController: UIViewController {
// Use MaterialLayout to easily align the tableView.
cardView.titleLabel = titleLabel
cardView.detailView = tableView
cardView.contentView = tableView
cardView.leftButtons = [closeButton]
cardView.rightButtons = [settingButton]
cardView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(cardView)
MaterialLayout.alignToParent(view, child: cardView, left: 10, right: 10, top: 100, bottom: 100)
}
......
......@@ -65,7 +65,6 @@ class ViewController: UIViewController, TextFieldDelegate {
/// Prepares the resign responder button.
private func prepareResignResponderButton() {
let btn: RaisedButton = RaisedButton()
btn.translatesAutoresizingMaskIntoConstraints = false
btn.addTarget(self, action: #selector(handleResignResponderButton), forControlEvents: .TouchUpInside)
btn.setTitle("Resign", forState: .Normal)
btn.setTitleColor(MaterialColor.blue.base, forState: .Normal)
......@@ -93,8 +92,6 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField.textAlignment = .Center
nameField.clearButtonMode = .WhileEditing
// The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly.
nameField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(nameField)
// Size the TextField to the maximum width, less 40 pixels on either side
......@@ -129,8 +126,6 @@ class ViewController: UIViewController, TextFieldDelegate {
// Setting the visibilityFlatButton color.
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)
// Size the TextField to the maximum width, less 40 pixels on either side
......
......@@ -76,7 +76,6 @@ class ViewController: UIViewController, TextDelegate {
textView.titleLabelActiveColor = MaterialColor.blue.accent3
view.addSubview(textView)
textView!.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: textView!, top: 124, left: 24, bottom: 24, right: 24)
}
......
......@@ -57,18 +57,12 @@ class ViewController: UIViewController {
toolbar = Toolbar()
// Title label.
let titleLabel: UILabel = UILabel()
titleLabel.text = "Material"
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regular
toolbar.titleLabel.text = "Material"
toolbar.titleLabel.textColor = MaterialColor.white
// Detail label.
let detailLabel: UILabel = UILabel()
detailLabel.text = "Build Beautiful Software"
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regular
toolbar.detailLabel.text = "Build Beautiful Software"
toolbar.detailLabel.textColor = MaterialColor.white
var image: UIImage? = MaterialIcon.cm.menu
......@@ -97,8 +91,6 @@ class ViewController: UIViewController {
*/
toolbar.statusBarStyle = .LightContent
toolbar.backgroundColor = MaterialColor.blue.base
toolbar.titleLabel = titleLabel
toolbar.detailLabel = detailLabel
toolbar.leftControls = [menuButton]
toolbar.rightControls = [switchControl, searchButton]
......
......@@ -7,12 +7,11 @@
objects = {
/* 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 */; };
96F2F1D71C97A55B00A5FE27 /* AppToolbarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1CE1C97A55B00A5FE27 /* AppToolbarController.swift */; };
96F2F1D81C97A55B00A5FE27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1CF1C97A55B00A5FE27 /* Assets.xcassets */; };
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 */; };
/* End PBXBuildFile section */
......@@ -30,13 +29,12 @@
/* End PBXCopyFilesBuildPhase 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; };
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>"; };
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>"; };
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>"; };
96F2F1D51C97A55B00A5FE27 /* YellowViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YellowViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -73,8 +71,7 @@
children = (
96F2F1CD1C97A55B00A5FE27 /* AppDelegate.swift */,
96F2F1CE1C97A55B00A5FE27 /* AppToolbarController.swift */,
96F2F1D21C97A55B00A5FE27 /* BlueViewController.swift */,
96F2F1D31C97A55B00A5FE27 /* GreenViewController.swift */,
9692C9281CE44C0C008C2766 /* GreenViewController.swift */,
96F2F1D51C97A55B00A5FE27 /* YellowViewController.swift */,
96F2F1CF1C97A55B00A5FE27 /* Assets.xcassets */,
96F2F1D01C97A55B00A5FE27 /* LaunchScreen.storyboard */,
......@@ -154,11 +151,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
96F2F1DB1C97A55B00A5FE27 /* GreenViewController.swift in Sources */,
96F2F1D71C97A55B00A5FE27 /* AppToolbarController.swift in Sources */,
96F2F1DA1C97A55B00A5FE27 /* BlueViewController.swift in Sources */,
96F2F1D61C97A55B00A5FE27 /* AppDelegate.swift in Sources */,
96F2F1DD1C97A55B00A5FE27 /* YellowViewController.swift in Sources */,
9692C92A1CE44C0C008C2766 /* GreenViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -59,14 +59,9 @@ class AppToolbarController: ToolbarController {
view.backgroundColor = MaterialColor.black
}
/// Toggle SideNavigationController left UIViewController.
internal func handleMenuButton() {
transitionFromRootViewController(GreenViewController(), options: [.TransitionCrossDissolve])
}
/// Toggle SideNavigationController right UIViewController.
internal func handleSearchButton() {
floatingViewController = BlueViewController()
floatingViewController = GreenViewController()
MaterialAnimation.delay(1.5) { [weak self] in
// Removes the ViewController from the view stack.
......@@ -77,32 +72,28 @@ class AppToolbarController: ToolbarController {
/// Prepares the toolbar.
private func prepareToolbar() {
// Title label.
let titleLabel: UILabel = UILabel()
titleLabel.text = "Material"
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regular
toolbar.titleLabel.text = "Material"
toolbar.titleLabel.textAlignment = .Left
toolbar.titleLabel.textColor = MaterialColor.white
toolbar.titleLabel.font = RobotoFont.regular
// Detail label. Uncomment the code below to use a detail label.
// let detailLabel: UILabel = UILabel()
// detailLabel.text = "Build Beautiful Software"
// detailLabel.textAlignment = .Left
// detailLabel.textColor = MaterialColor.white
// detailLabel.font = RobotoFont.regular
// toolbar.detailLabel = detailLabel
// toolbar.detailLabel.text = "Build Beautiful Software"
// toolbar.detailLabel.textAlignment = .Left
// toolbar.detailLabel.textColor = MaterialColor.white
// toolbar.detailLabel.font = RobotoFont.regular
var image: UIImage? = MaterialIcon.cm.menu
// Menu button.
let menuButton: IconButton = IconButton()
menuButton.tintColor = MaterialColor.white
menuButton.pulseColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
menuButton.addTarget(self, action: #selector(handleMenuButton), forControlEvents: .TouchUpInside)
// Switch control.
let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small)
switchControl.delegate = self
// Search button.
image = MaterialIcon.cm.search
......@@ -112,16 +103,8 @@ class AppToolbarController: ToolbarController {
searchButton.setImage(image, forState: .Highlighted)
searchButton.addTarget(self, action: #selector(handleSearchButton), forControlEvents: .TouchUpInside)
toolbar.backgroundColor = MaterialColor.blue.base
toolbar.titleLabel = titleLabel
toolbar.leftControls = [menuButton]
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 {
let detailLabel: UILabel = UILabel()
detailLabel.text = "It’s been a while, have you read any new books lately?"
detailLabel.numberOfLines = 0
topCardView.detailView = detailLabel
topCardView.contentView = detailLabel
// Yes button.
let btn1: FlatButton = FlatButton()
......@@ -91,7 +91,7 @@ class ViewController: UIViewController {
let detailLabel: UILabel = UILabel()
detailLabel.text = "It’s been a while, have you read any new books lately?"
detailLabel.numberOfLines = 0
bottomCardView.detailView = detailLabel
bottomCardView.contentView = detailLabel
// Yes button.
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 {
fabButton.addTarget(self, action: #selector(handleFabButton), forControlEvents: .TouchUpInside)
view.addSubview(fabButton)
fabButton.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromBottomRight(view, child: fabButton, bottom: 16, right: 16)
MaterialLayout.size(view, child: fabButton, width: 64, height: 64)
}
......
......@@ -78,20 +78,12 @@ class ViewController: UIViewController {
toolbar.statusBarStyle = .LightContent
// Title label.
let titleLabel: UILabel = UILabel()
titleLabel.text = "Material"
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regular
toolbar.titleLabel = titleLabel
toolbar.titleLabel.text = "Material"
toolbar.titleLabel.textColor = MaterialColor.white
// Detail label.
let detailLabel: UILabel = UILabel()
detailLabel.text = "Build Beautiful Software"
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regular
toolbar.detailLabel = detailLabel
toolbar.detailLabel.text = "Build Beautiful Software"
toolbar.detailLabel.textColor = MaterialColor.white
// Menu button.
let img1: UIImage? = MaterialIcon.cm.menu
......
......@@ -233,7 +233,6 @@ public class BottomTabBar : UITabBar {
super.didMoveToSuperview()
if autoLayoutToSuperview {
if let v: UIView = superview {
translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromBottom(v, child: self)
MaterialLayout.alignToParentHorizontally(v, child: self)
}
......
......@@ -113,35 +113,33 @@ public class CardView : MaterialPulseView {
*/
@IBInspectable public var titleLabel: UILabel? {
didSet {
titleLabel?.translatesAutoresizingMaskIntoConstraints = false
reloadView()
}
}
/**
:name: detailViewInsets
:name: contentViewInsets
*/
public var detailViewInsetPreset: MaterialEdgeInset = .Square2 {
public var contentViewInsetPreset: MaterialEdgeInset = .Square2 {
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 {
reloadView()
}
}
/**
:name: detailView
:name: contentView
*/
@IBInspectable public var detailView: UIView? {
@IBInspectable public var contentView: UIView? {
didSet {
detailView?.translatesAutoresizingMaskIntoConstraints = false
reloadView()
}
}
......@@ -169,11 +167,6 @@ public class CardView : MaterialPulseView {
*/
public var leftButtons: Array<UIButton>? {
didSet {
if let v = leftButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView()
}
}
......@@ -201,11 +194,6 @@ public class CardView : MaterialPulseView {
*/
public var rightButtons: Array<UIButton>? {
didSet {
if let v = rightButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView()
}
}
......@@ -234,9 +222,9 @@ public class CardView : MaterialPulseView {
/**
: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)
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 {
if nil != titleLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInset.top + titleLabelInset.top
} else if nil != detailView {
} else if nil != contentView {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInset.top + detailViewInset.top
metrics["insetTop"] = contentInset.top + contentViewInset.top
}
// title
......@@ -295,20 +283,20 @@ public class CardView : MaterialPulseView {
}
// detail
if let v: UIView = detailView {
if let v: UIView = contentView {
addSubview(v)
if nil == titleLabel {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + detailViewInset.top
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentViewInset.top
} else {
verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInset.bottom + detailViewInset.top
metrics["insetB"] = titleLabelInset.bottom + contentViewInset.top
}
verticalFormat += "-[detailView]"
views["detailView"] = v
verticalFormat += "-[contentView]"
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
......@@ -382,11 +370,11 @@ public class CardView : MaterialPulseView {
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
}
if nil != detailView {
if nil != contentView {
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 {
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 {
if nil == metrics["insetC"] {
......@@ -430,10 +418,10 @@ public class CardView : MaterialPulseView {
/**
: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.titleLabel = titleLabel
self.detailView = detailView
self.contentView = contentView
self.leftButtons = leftButtons
self.rightButtons = rightButtons
}
......
......@@ -143,42 +143,56 @@ public class ControlView : MaterialView {
public override func layoutSubviews() {
super.layoutSubviews()
if willRenderView {
// Size of single grid column.
if let g: CGFloat = width / CGFloat(0 < grid.axis.columns ? grid.axis.columns : 1) {
let factor: CGFloat = 24
if let g: Int = Int(width / factor) {
let columns: Int = g + 1
frame.origin = CGPointZero
frame.size = intrinsicContentSize()
grid.views = []
contentView.grid.views = []
contentView.grid.columns = grid.axis.columns
grid.axis.columns = columns
contentView.grid.columns = columns
// leftControls
if let v: Array<UIControl> = leftControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize().width
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets = UIEdgeInsetsZero
}
c.frame.size.height = height - contentInset.top - contentInset.bottom
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsetsZero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / factor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c)
}
}
addSubview(contentView)
grid.views?.append(contentView)
// rightControls
if let v: Array<UIControl> = rightControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize().width
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets = UIEdgeInsetsZero
}
c.frame.size.height = height - contentInset.top - contentInset.bottom
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsetsZero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / factor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c)
}
}
grid.contentInset = contentInset
grid.spacing = spacing
grid.reloadLayout()
}
}
......@@ -196,12 +210,6 @@ public class ControlView : MaterialView {
prepareContentView()
}
/// Prepares the contentView.
public func prepareContentView() {
contentView.backgroundColor = nil
addSubview(contentView)
}
/**
Used to trigger property changes that initializers avoid.
- Parameter leftControls: An Array of UIControls that go on the left side.
......@@ -211,4 +219,10 @@ public class ControlView : MaterialView {
self.leftControls = leftControls
self.rightControls = rightControls
}
/// Prepares the contentView.
private func prepareContentView() {
contentView.backgroundColor = nil
addSubview(contentView)
}
}
......@@ -206,35 +206,33 @@ public class ImageCardView : MaterialPulseView {
*/
@IBInspectable public var titleLabel: UILabel? {
didSet {
titleLabel?.translatesAutoresizingMaskIntoConstraints = false
reloadView()
}
}
/**
:name: detailViewInsets
:name: contentViewInsets
*/
public var detailViewInsetPreset: MaterialEdgeInset = .Square2 {
public var contentViewInsetPreset: MaterialEdgeInset = .Square2 {
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 {
reloadView()
}
}
/**
:name: detailView
:name: contentView
*/
@IBInspectable public var detailView: UIView? {
@IBInspectable public var contentView: UIView? {
didSet {
detailView?.translatesAutoresizingMaskIntoConstraints = false
reloadView()
}
}
......@@ -262,11 +260,6 @@ public class ImageCardView : MaterialPulseView {
*/
public var leftButtons: Array<UIButton>? {
didSet {
if let v = leftButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView()
}
}
......@@ -294,11 +287,6 @@ public class ImageCardView : MaterialPulseView {
*/
public var rightButtons: Array<UIButton>? {
didSet {
if let v = rightButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView()
}
}
......@@ -327,9 +315,9 @@ public class ImageCardView : MaterialPulseView {
/**
: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)
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 {
} else if nil != titleLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInset.top + titleLabelInset.top
} else if nil != detailView {
} else if nil != contentView {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInset.top + detailViewInset.top
metrics["insetTop"] = contentInset.top + contentViewInset.top
}
// title
......@@ -398,20 +386,20 @@ public class ImageCardView : MaterialPulseView {
}
// detail
if let v: UIView = detailView {
if let v: UIView = contentView {
addSubview(v)
if nil == imageLayer?.contents && nil != titleLabel {
verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInset.bottom + detailViewInset.top
metrics["insetB"] = titleLabelInset.bottom + contentViewInset.top
} else {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + detailViewInset.top
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentViewInset.top
}
verticalFormat += "-[detailView]"
views["detailView"] = v
verticalFormat += "-[contentView]"
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
......@@ -486,11 +474,11 @@ public class ImageCardView : MaterialPulseView {
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
}
if nil != detailView {
if nil != contentView {
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 {
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 {
if nil == metrics["insetC"] {
......@@ -501,7 +489,7 @@ public class ImageCardView : MaterialPulseView {
} else if nil != metrics["insetC"] {
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 {
verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0]
......@@ -515,9 +503,9 @@ public class ImageCardView : MaterialPulseView {
}
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 {
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 0 < leftButtons?.count {
......@@ -583,10 +571,10 @@ public class ImageCardView : MaterialPulseView {
/**
: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.titleLabel = titleLabel
self.detailView = detailView
self.contentView = contentView
self.leftButtons = leftButtons
self.rightButtons = rightButtons
}
......
......@@ -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
view's backing layer.
......
......@@ -32,6 +32,46 @@ import UIKit
@IBDesignable
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.
public var contentInsetPreset: MaterialEdgeInset {
get {
......
......@@ -31,35 +31,27 @@
import UIKit
public struct MaterialLayout {
/**
:name: width
*/
/// Width
public static func width(parent: UIView, child: UIView, width: CGFloat = 0, options: NSLayoutFormatOptions = []) {
let metrics: Dictionary<String, AnyObject> = ["width" : width]
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint("H:[child(width)]", options: options, metrics: metrics, views: views))
}
/**
:name: height
*/
/// Height
public static func height(parent: UIView, child: UIView, height: CGFloat = 0, options: NSLayoutFormatOptions = []) {
let metrics: Dictionary<String, AnyObject> = ["height" : height]
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint("V:[child(height)]", options: options, metrics: metrics, views: views))
}
/**
:name: size
*/
/// Size
public static func size(parent: UIView, child: UIView, width: CGFloat = 0, height: CGFloat = 0, options: NSLayoutFormatOptions = []) {
MaterialLayout.width(parent, child: child, width: width)
MaterialLayout.height(parent, child: child, height: height)
}
/**
:name: alignToParentHorizontally
*/
/// AlignToParentHorizontally
public static func alignToParentHorizontally(parent: UIView, children: Array<UIView>, left: CGFloat = 0, right: CGFloat = 0, spacing: CGFloat = 0, options: NSLayoutFormatOptions = []) {
if 0 < children.count {
var format: String = "H:|-(left)-"
......@@ -75,9 +67,7 @@ public struct MaterialLayout {
}
}
/**
:name: alignToParentVertically
*/
/// AlignToParentVertically
public static func alignToParentVertically(parent: UIView, children: Array<UIView>, top: CGFloat = 0, bottom: CGFloat = 0, spacing: CGFloat = 0, options: NSLayoutFormatOptions = []) {
if 0 < children.count {
var format: String = "V:|-(top)-"
......@@ -93,92 +83,73 @@ public struct MaterialLayout {
}
}
/**
:name: alignToParentHorizontally
*/
/// AlignToParentHorizontally
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]))
}
/**
:name: alignToParentVertically
*/
/// AlignToParentVertically
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]))
}
/**
:name: alignToParent
*/
/// AlignToParent
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)
alignToParentVertically(parent, child: child, top: top, bottom: bottom)
}
/**
:name: alignFromTopLeft
*/
/// AlignFromTopLeft
public static func alignFromTopLeft(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, options: NSLayoutFormatOptions = []) {
alignFromTop(parent, child: child, top: top)
alignFromLeft(parent, child: child, left: left)
}
/**
:name: alignFromTopRight
*/
/// AlignFromTopRight
public static func alignFromTopRight(parent: UIView, child: UIView, top: CGFloat = 0, right: CGFloat = 0, options: NSLayoutFormatOptions = []) {
alignFromTop(parent, child: child, top: top)
alignFromRight(parent, child: child, right: right)
}
/**
:name: alignFromBottomLeft
*/
/// AlignFromBottomLeft
public static func alignFromBottomLeft(parent: UIView, child: UIView, bottom: CGFloat = 0, left: CGFloat = 0, options: NSLayoutFormatOptions = []) {
alignFromBottom(parent, child: child, bottom: bottom)
alignFromLeft(parent, child: child, left: left)
}
/**
:name: alignFromBottomRight
*/
/// AlignFromBottomRight
public static func alignFromBottomRight(parent: UIView, child: UIView, bottom: CGFloat = 0, right: CGFloat = 0, options: NSLayoutFormatOptions = []) {
alignFromBottom(parent, child: child, bottom: bottom)
alignFromRight(parent, child: child, right: right)
}
/**
:name: alignFromTop
*/
/// AlignFromTop
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]))
}
/**
:name: alignFromLeft
*/
/// AlignFromLeft
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]))
}
/**
:name: alignFromBottom
*/
/// AlignFromBottom
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]))
}
/**
:name: alignFromRight
*/
/// AlignFromRight
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]))
}
/**
:name: constraint
*/
/// Constraint
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(
format,
options: options,
......
......@@ -114,15 +114,21 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
*/
public func navigationBar(navigationBar: UINavigationBar, shouldPushItem item: UINavigationItem) -> Bool {
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 {
c.append(v.backButton)
c.append(backButton)
item.leftControls = c
} 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)
}
return true
......
......@@ -34,20 +34,20 @@ import UIKit
private var MaterialAssociatedObjectNavigationItemKey: UInt8 = 0
public class MaterialAssociatedObjectNavigationItem {
/// Portrait inset.
public var portraitInset: CGFloat
/// Back Button.
public var backButton: IconButton?
/// Landscape inset.
public var landscapeInset: CGFloat
/// Detail View.
public var detailView: UIView?
/// Content View.
public var contentView: UIView?
/// Title label.
public var titleLabel: UILabel?
public private(set) var titleLabel: UILabel!
/// Detail text.
public var detail: String?
/// Detail label.
public var detailLabel: UILabel?
public private(set) var detailLabel: UILabel!
/// Left controls.
public var leftControls: Array<UIControl>?
......@@ -55,9 +55,24 @@ public class MaterialAssociatedObjectNavigationItem {
/// Right controls.
public var rightControls: Array<UIControl>?
public init(portraitInset: CGFloat, landscapeInset: CGFloat) {
self.portraitInset = portraitInset
self.landscapeInset = landscapeInset
/// Initializer.
public init() {
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 {
public internal(set) var item: MaterialAssociatedObjectNavigationItem {
get {
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) {
......@@ -74,48 +89,48 @@ public extension UINavigationItem {
}
}
/// Portrait inset.
public var portraitInset: CGFloat {
/// Back Button.
public internal(set) var backButton: IconButton? {
get {
return item.portraitInset
return item.backButton
}
set(value) {
item.portraitInset = value
item.backButton = value
}
}
/// Landscape inset.
public var landscapeInset: CGFloat {
/// Content View.
public internal(set) var contentView: UIView? {
get {
return item.landscapeInset
return item.contentView
}
set(value) {
item.landscapeInset = value
item.contentView = value
}
}
/// Detail View.
public var detailView: UIView? {
/// Title Label.
public internal(set) var titleLabel: UILabel {
get {
return item.detailView
return item.titleLabel
}
set(value) {
item.detailView = value
item.titleLabel = value
}
}
/// Title Label.
public var titleLabel: UILabel? {
/// Detail text.
public var detail: String? {
get {
return item.titleLabel
return item.detail
}
set(value) {
item.titleLabel = value
item.detail = value
}
}
/// Detail Label.
public var detailLabel: UILabel? {
public internal(set) var detailLabel: UILabel {
get {
return item.detailLabel
}
......
......@@ -93,15 +93,20 @@ public class SearchBar : StatusBarView {
public override func layoutSubviews() {
super.layoutSubviews()
if willRenderView {
contentView.grid.views?.append(textField)
contentView.grid.reloadLayout()
textField.frame = contentView.bounds
layoutClearButton()
}
}
/// Prepares the contentView.
public override func prepareContentView() {
super.prepareContentView()
/**
Prepares the view instance when intialized. When subclassing,
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()
prepareClearButton()
}
......
......@@ -74,7 +74,7 @@ public class StatusBarView : ControlView {
width = MaterialDevice.width
}
grid.axis.columns = Int(width / 56)
grid.axis.columns = Int(width / 24)
// General alignment.
if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape {
......
......@@ -479,7 +479,6 @@ public class TextView: UITextView {
/// prepares the placeholderLabel property.
private func preparePlaceholderLabel() {
if let v: UILabel = placeholderLabel {
v.translatesAutoresizingMaskIntoConstraints = false
v.font = font
v.textAlignment = textAlignment
v.numberOfLines = 0
......
......@@ -32,91 +32,65 @@ import UIKit
public class Toolbar : StatusBarView {
/// Title label.
public var titleLabel: UILabel? {
didSet {
if let v: UILabel = titleLabel {
contentView.addSubview(v)
}
layoutSubviews()
}
}
public private(set) var titleLabel: UILabel!
/// Detail label.
public 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 private(set) var detailLabel: UILabel!
public override func layoutSubviews() {
super.layoutSubviews()
if willRenderView {
contentView.grid.views = []
// TitleView alignment.
if let t: UILabel = titleLabel {
t.grid.rows = 1
contentView.grid.views?.append(t)
if let _: String = titleLabel.text {
if nil == titleLabel.superview {
contentView.addSubview(titleLabel)
}
if let d: UILabel = detailLabel {
t.font = t.font.fontWithSize(17)
d.grid.rows = 1
d.font = d.font.fontWithSize(12)
if let _: String = detailLabel.text {
if nil == detailLabel.superview {
contentView.addSubview(detailLabel)
}
contentView.grid.axis.rows = 2
contentView.grid.views?.append(d)
titleLabel.sizeToFit()
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 {
t.font = t.font?.fontWithSize(20)
contentView.grid.axis.rows = 1
detailLabel.removeFromSuperview()
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.
- 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.
Prepares the view instance when intialized. When subclassing,
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.
*/
internal func prepareProperties(titleLabel: UILabel?, detailLabel: UILabel?, leftControls: Array<UIControl>?, rightControls: Array<UIControl>?) {
prepareProperties(leftControls, rightControls: rightControls)
self.titleLabel = titleLabel
self.detailLabel = detailLabel
public override func prepareView() {
super.prepareView()
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
}
}
\ 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