Commit a1629384 by Daniel Dahan

updated NavigationBarView with auto handling for orientation changes

parent fedaf01a
...@@ -40,7 +40,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate { ...@@ -40,7 +40,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareSmallMaterialSwitch() prepareSmallMaterialSwitch()
prepareNormalMaterialSwitch() prepareDefaultMaterialSwitch()
prepareLargeMaterialSwitch() prepareLargeMaterialSwitch()
prepareLightOnDisabledMaterialSwitch() prepareLightOnDisabledMaterialSwitch()
prepareLightOffDisabledMaterialSwitch() prepareLightOffDisabledMaterialSwitch()
...@@ -55,76 +55,75 @@ class ViewController: UIViewController, MaterialSwitchDelegate { ...@@ -55,76 +55,75 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
/// Prepares the Small MaterialSwitch. /// Prepares the Small MaterialSwitch.
private func prepareSmallMaterialSwitch() { private func prepareSmallMaterialSwitch() {
let materialSwitch: MaterialSwitch = MaterialSwitch(state: .Off, style: .Light, size: .Small) let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .Light, size: .Small)
materialSwitch.center = view.center switchControl.center = view.center
materialSwitch.y -= 100 switchControl.y -= 100
materialSwitch.delegate = self switchControl.delegate = self
view.addSubview(materialSwitch) view.addSubview(switchControl)
} }
/// Prepares the Normal MaterialSwitch. /// Prepares the Default MaterialSwitch.
private func prepareNormalMaterialSwitch() { private func prepareDefaultMaterialSwitch() {
let materialSwitch: MaterialSwitch = MaterialSwitch(state: .On, style: .Light, size: .Normal) let switchControl: MaterialSwitch = MaterialSwitch(state: .On, style: .Light)
materialSwitch.delegate = self switchControl.delegate = self
view.addSubview(materialSwitch) view.addSubview(switchControl)
materialSwitch.translatesAutoresizingMaskIntoConstraints = false switchControl.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.size(view, child: materialSwitch, width: materialSwitch.width, height: materialSwitch.height) MaterialLayout.alignFromBottomRight(view, child: switchControl, bottom: 16, right: 16)
MaterialLayout.alignFromBottomRight(view, child: materialSwitch, bottom: 16, right: 16)
} }
/// Prepares the Large MaterialSwitch. /// Prepares the Large MaterialSwitch.
private func prepareLargeMaterialSwitch() { private func prepareLargeMaterialSwitch() {
let image: UIImage? = UIImage(named: "ic_alarm_white_18pt") let image: UIImage? = UIImage(named: "ic_alarm_white_18pt")
let materialSwitch: MaterialSwitch = MaterialSwitch(state: .Off, style: .Light, size: .Large) let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .Light, size: .Large)
materialSwitch.center = view.center switchControl.center = view.center
materialSwitch.y -= 50 switchControl.y -= 50
materialSwitch.delegate = self switchControl.delegate = self
materialSwitch.button.setImage(image, forState: .Normal) switchControl.button.setImage(image, forState: .Normal)
materialSwitch.button.setImage(image, forState: .Highlighted) switchControl.button.setImage(image, forState: .Highlighted)
view.addSubview(materialSwitch) view.addSubview(switchControl)
} }
/// Prepares the Light On enabled = false MaterialSwitch. /// Prepares the Light On enabled = false MaterialSwitch.
private func prepareLightOnDisabledMaterialSwitch() { private func prepareLightOnDisabledMaterialSwitch() {
let materialSwitch: MaterialSwitch = MaterialSwitch(state: .On, style: .Light, size: .Normal) let switchControl: MaterialSwitch = MaterialSwitch(state: .On, style: .Light)
materialSwitch.enabled = false switchControl.enabled = false
materialSwitch.center = view.center switchControl.center = view.center
materialSwitch.delegate = self switchControl.delegate = self
view.addSubview(materialSwitch) view.addSubview(switchControl)
} }
/// Prepares the Light Off enabled = false MaterialSwitch. /// Prepares the Light Off enabled = false MaterialSwitch.
private func prepareLightOffDisabledMaterialSwitch() { private func prepareLightOffDisabledMaterialSwitch() {
let materialSwitch: MaterialSwitch = MaterialSwitch(state: .Off, style: .Light, size: .Normal) let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .Light)
materialSwitch.enabled = false switchControl.enabled = false
materialSwitch.center = view.center switchControl.center = view.center
materialSwitch.y += 50 switchControl.y += 50
materialSwitch.delegate = self switchControl.delegate = self
view.addSubview(materialSwitch) view.addSubview(switchControl)
} }
/// Prepares the Dark On enabled = false MaterialSwitch. /// Prepares the Dark On enabled = false MaterialSwitch.
private func prepareDarkOnDisabledMaterialSwitch() { private func prepareDarkOnDisabledMaterialSwitch() {
let materialSwitch: MaterialSwitch = MaterialSwitch(state: .On, style: .Dark, size: .Normal) let switchControl: MaterialSwitch = MaterialSwitch(state: .On, style: .Dark)
materialSwitch.enabled = false switchControl.enabled = false
materialSwitch.center = view.center switchControl.center = view.center
materialSwitch.y += 100 switchControl.y += 100
materialSwitch.delegate = self switchControl.delegate = self
view.addSubview(materialSwitch) view.addSubview(switchControl)
} }
/// Prepares the Dark On enabled = false MaterialSwitch. /// Prepares the Dark On enabled = false MaterialSwitch.
private func prepareDarkOffDisabledMaterialSwitch() { private func prepareDarkOffDisabledMaterialSwitch() {
let materialSwitch: MaterialSwitch = MaterialSwitch(state: .Off, style: .Dark, size: .Normal) let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .Dark)
materialSwitch.enabled = false switchControl.enabled = false
materialSwitch.center = view.center switchControl.center = view.center
materialSwitch.y += 150 switchControl.y += 150
materialSwitch.delegate = self switchControl.delegate = self
view.addSubview(materialSwitch) view.addSubview(switchControl)
} }
internal func materialSwitchStateChanged(control: MaterialSwitch, state: MaterialSwitchState) { internal func switchControlStateChanged(control: MaterialSwitch, state: MaterialSwitchState) {
print("MaterialSwitch - Size: \(control.switchSize) State: \(state)") print("MaterialSwitch - Size: \(control.switchSize) State: \(state)")
} }
} }
...@@ -41,17 +41,6 @@ class ViewController: UIViewController { ...@@ -41,17 +41,6 @@ class ViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
/*
Examples of using NavigationBarView.
Uncomment different examples and read
the comments below.
*/
// prepareGeneralUsageExample()
// prepareOrientationSupportExample()
// prepareDetailLabelExample()
// prepareBackgroundImageExample()
// prepareButtonExample()
prepareAlignTitleAndDetailLabelToLeftExample() prepareAlignTitleAndDetailLabelToLeftExample()
} }
...@@ -60,182 +49,6 @@ class ViewController: UIViewController { ...@@ -60,182 +49,6 @@ class ViewController: UIViewController {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
} }
/// Prepares a general usage example.
private func prepareGeneralUsageExample() {
let navigationBarView: NavigationBarView = NavigationBarView()
navigationBarView.backgroundColor = MaterialColor.blue.darken1
/*
To lighten the status bar - add the
"View controller-based status bar appearance = NO"
to your info.plist file and set the following property.
*/
navigationBarView.statusBarStyle = .LightContent
// Title label.
let titleLabel: UILabel = UILabel()
titleLabel.text = "Material"
titleLabel.textAlignment = .Center
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(20)
navigationBarView.titleLabel = titleLabel
// Add NavigationBarView without support for orientation change.
view.addSubview(navigationBarView)
}
/// Prepare an example using MaterialLayout that support orientation change.
private func prepareOrientationSupportExample() {
let navigationBarView: NavigationBarView = NavigationBarView()
navigationBarView.backgroundColor = MaterialColor.red.darken1
/*
To lighten the status bar - add the
"View controller-based status bar appearance = NO"
to your info.plist file and set the following property.
*/
navigationBarView.statusBarStyle = .LightContent
// Title label.
let titleLabel: UILabel = UILabel()
titleLabel.text = "Material"
titleLabel.textAlignment = .Center
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(20)
navigationBarView.titleLabel = titleLabel
// To support orientation changes, use MaterialLayout.
view.addSubview(navigationBarView)
navigationBarView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: navigationBarView)
MaterialLayout.alignToParentHorizontally(view, child: navigationBarView)
MaterialLayout.height(view, child: navigationBarView, height: 70)
}
/// Prepares an example that uses a detailLabel.
private func prepareDetailLabelExample() {
let navigationBarView: NavigationBarView = NavigationBarView()
navigationBarView.backgroundColor = MaterialColor.purple.darken1
/*
To lighten the status bar - add the
"View controller-based status bar appearance = NO"
to your info.plist file and set the following property.
*/
navigationBarView.statusBarStyle = .LightContent
// Title label.
let titleLabel: UILabel = UILabel()
titleLabel.text = "Material"
titleLabel.textAlignment = .Center
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(20)
navigationBarView.titleLabel = titleLabel
// Detail label.
let detailLabel: UILabel = UILabel()
detailLabel.text = "Build Beautiful Software"
detailLabel.textAlignment = .Center
detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regularWithSize(12)
navigationBarView.detailLabel = detailLabel
// To support orientation changes, use MaterialLayout.
view.addSubview(navigationBarView)
navigationBarView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: navigationBarView)
MaterialLayout.alignToParentHorizontally(view, child: navigationBarView)
MaterialLayout.height(view, child: navigationBarView, height: 70)
}
/// Prepares an example that uses a background image.
private func prepareBackgroundImageExample() {
let navigationBarView: NavigationBarView = NavigationBarView()
navigationBarView.image = UIImage(named: "NavigationBarViewTexture")
navigationBarView.contentsGravity = .ResizeAspectFill
/*
To lighten the status bar - add the
"View controller-based status bar appearance = NO"
to your info.plist file and set the following property.
*/
navigationBarView.statusBarStyle = .LightContent
// Title label.
let titleLabel: UILabel = UILabel()
titleLabel.text = "Material"
titleLabel.textAlignment = .Center
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.boldWithSize(22)
navigationBarView.titleLabel = titleLabel
// To support orientation changes, use MaterialLayout.
view.addSubview(navigationBarView)
navigationBarView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: navigationBarView)
MaterialLayout.alignToParentHorizontally(view, child: navigationBarView)
MaterialLayout.height(view, child: navigationBarView, height: 70)
}
/// Prepares an example that uses buttons.
private func prepareButtonExample() {
let navigationBarView: NavigationBarView = NavigationBarView()
navigationBarView.backgroundColor = MaterialColor.blueGrey.darken4
/*
To lighten the status bar - add the
"View controller-based status bar appearance = NO"
to your info.plist file and set the following property.
*/
navigationBarView.statusBarStyle = .LightContent
// Title label.
let titleLabel: UILabel = UILabel()
titleLabel.text = "Material"
titleLabel.textAlignment = .Center
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(20)
navigationBarView.titleLabel = titleLabel
// Menu button.
let img1: UIImage? = UIImage(named: "ic_menu_white")
let btn1: FlatButton = FlatButton()
btn1.pulseColor = MaterialColor.white
btn1.pulseScale = false
btn1.setImage(img1, forState: .Normal)
btn1.setImage(img1, forState: .Highlighted)
// Star button.
let img2: UIImage? = UIImage(named: "ic_star_white")
let btn2: FlatButton = FlatButton()
btn2.pulseColor = MaterialColor.white
btn2.pulseScale = false
btn2.setImage(img2, forState: .Normal)
btn2.setImage(img2, forState: .Highlighted)
// Search button.
let img3: UIImage? = UIImage(named: "ic_search_white")
let btn3: FlatButton = FlatButton()
btn3.pulseColor = MaterialColor.white
btn3.pulseScale = false
btn3.setImage(img3, forState: .Normal)
btn3.setImage(img3, forState: .Highlighted)
// Add buttons to left side.
navigationBarView.leftControls = [btn1]
// Add buttons to right side.
navigationBarView.rightControls = [btn2, btn3]
// To support orientation changes, use MaterialLayout.
view.addSubview(navigationBarView)
navigationBarView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: navigationBarView)
MaterialLayout.alignToParentHorizontally(view, child: navigationBarView)
MaterialLayout.height(view, child: navigationBarView, height: 70)
}
/// Prepares a text alignment example. /// Prepares a text alignment example.
private func prepareAlignTitleAndDetailLabelToLeftExample() { private func prepareAlignTitleAndDetailLabelToLeftExample() {
let navigationBarView: NavigationBarView = NavigationBarView() let navigationBarView: NavigationBarView = NavigationBarView()
...@@ -253,7 +66,7 @@ class ViewController: UIViewController { ...@@ -253,7 +66,7 @@ class ViewController: UIViewController {
titleLabel.text = "Material" titleLabel.text = "Material"
titleLabel.textAlignment = .Left titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(22) titleLabel.font = RobotoFont.regularWithSize(17)
navigationBarView.titleLabel = titleLabel navigationBarView.titleLabel = titleLabel
// Detail label. // Detail label.
...@@ -261,40 +74,35 @@ class ViewController: UIViewController { ...@@ -261,40 +74,35 @@ class ViewController: UIViewController {
detailLabel.text = "Build Beautiful Software" detailLabel.text = "Build Beautiful Software"
detailLabel.textAlignment = .Left detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regularWithSize(10) detailLabel.font = RobotoFont.regularWithSize(12)
// navigationBarView.detailLabel = detailLabel navigationBarView.detailLabel = detailLabel
// Menu button. // Menu button.
let img1: UIImage? = UIImage(named: "ic_menu_white") let img1: UIImage? = UIImage(named: "ic_menu_white")
let btn1: FlatButton = FlatButton() let menuButton: FlatButton = FlatButton()
btn1.pulseColor = MaterialColor.white menuButton.pulseColor = nil
btn1.pulseScale = false menuButton.pulseScale = false
btn1.setImage(img1, forState: .Normal) menuButton.setImage(img1, forState: .Normal)
btn1.setImage(img1, forState: .Highlighted) menuButton.setImage(img1, forState: .Highlighted)
// Star button. // Star button.
let materialSwitch: MaterialSwitch = MaterialSwitch(state: .On, style: .Light, size: .Normal) let switchControl: MaterialSwitch = MaterialSwitch(state: .On, style: .Light)
// Search button. // Search button.
let img3: UIImage? = UIImage(named: "ic_search_white") let img3: UIImage? = UIImage(named: "ic_search_white")
let btn3: FlatButton = FlatButton() let searchButton: FlatButton = FlatButton()
btn3.pulseColor = MaterialColor.white searchButton.pulseColor = nil
btn3.pulseScale = false searchButton.pulseScale = false
btn3.setImage(img3, forState: .Normal) searchButton.setImage(img3, forState: .Normal)
btn3.setImage(img3, forState: .Highlighted) searchButton.setImage(img3, forState: .Highlighted)
// Add buttons to left side. // Add controls to left side.
navigationBarView.leftControls = [btn1] navigationBarView.leftControls = [menuButton]
// Add buttons to right side. // Add controls to right side.
navigationBarView.rightControls = [materialSwitch, btn3] navigationBarView.rightControls = [switchControl, searchButton]
// To support orientation changes, use MaterialLayout.
view.addSubview(navigationBarView) view.addSubview(navigationBarView)
navigationBarView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: navigationBarView)
MaterialLayout.alignToParentHorizontally(view, child: navigationBarView)
MaterialLayout.height(view, child: navigationBarView, height: 70)
} }
} }
...@@ -81,7 +81,7 @@ class ViewController: UIViewController { ...@@ -81,7 +81,7 @@ class ViewController: UIViewController {
searchBarView.textField.font = RobotoFont.regularWithSize(22) searchBarView.textField.font = RobotoFont.regularWithSize(22)
searchBarView.leftControls = [menuButton] searchBarView.leftControls = [menuButton]
searchBarView.rightControls = [searchButton] // searchBarView.rightControls = [searchButton]
view.addSubview(searchBarView) view.addSubview(searchBarView)
searchBarView.translatesAutoresizingMaskIntoConstraints = false searchBarView.translatesAutoresizingMaskIntoConstraints = false
......
...@@ -69,17 +69,15 @@ Material is a growing project and will encounter changes throughout its developm ...@@ -69,17 +69,15 @@ Material is a growing project and will encounter changes throughout its developm
## Upcoming ## Upcoming
* SearchBarView * MenuViewController
* SearchBarViewController * SearchBarViewController
* TabView * TabView
* TabViewController * TabViewController
* Scrolling Techniques * Scrolling Techniques
* Dialogs
* Snackbar * Snackbar
* ProgressBar (circular and horizontal) * ProgressBar (circular and horizontal)
* DatePicker * DatePicker
* TimePicker * TimePicker
* Switch Control
* More Examples * More Examples
<a name="materialcolor"></a> <a name="materialcolor"></a>
......
...@@ -297,7 +297,7 @@ public class MaterialButton : UIButton { ...@@ -297,7 +297,7 @@ public class MaterialButton : UIButton {
prepareView() prepareView()
} }
/// A convenience initializer that is mostly used with AutoLayout. /// A convenience initializer.
public convenience init() { public convenience init() {
self.init(frame: CGRectNull) self.init(frame: CGRectNull)
} }
...@@ -406,8 +406,8 @@ public class MaterialButton : UIButton { ...@@ -406,8 +406,8 @@ public class MaterialButton : UIButton {
} }
if let v: CFTimeInterval = pulseAnimation(point!) { if let v: CFTimeInterval = pulseAnimation(point!) {
MaterialAnimation.delay(v) { [unowned self] in MaterialAnimation.delay(v) { [weak self] in
self.shrinkAnimation() self?.shrinkAnimation()
} }
} }
} }
...@@ -483,12 +483,12 @@ public class MaterialButton : UIButton { ...@@ -483,12 +483,12 @@ public class MaterialButton : UIButton {
pulseLayer.hidden = false pulseLayer.hidden = false
} }
pulseLayer.addAnimation(MaterialAnimation.scale(3 * d, duration: t), forKey: nil) pulseLayer.addAnimation(MaterialAnimation.scale(3 * d, duration: t), forKey: nil)
MaterialAnimation.delay(t) { [unowned self] in MaterialAnimation.delay(t) { [weak self] in
if nil != self.pulseColor && 0 < self.pulseColorOpacity { if nil != self && nil != self!.pulseColor && 0 < self!.pulseColorOpacity {
MaterialAnimation.animateWithDuration(t, animations: { MaterialAnimation.animateWithDuration(t, animations: {
pulseLayer.hidden = true pulseLayer.hidden = true
}) { }) {
pulseLayer.removeFromSuperlayer() pulseLayer.removeFromSuperlayer()
} }
} }
} }
......
...@@ -84,8 +84,8 @@ public class MaterialPulseView : MaterialView { ...@@ -84,8 +84,8 @@ public class MaterialPulseView : MaterialView {
} }
if let v: CFTimeInterval = pulseAnimation(point!) { if let v: CFTimeInterval = pulseAnimation(point!) {
MaterialAnimation.delay(v) { [unowned self] in MaterialAnimation.delay(v) { [weak self] in
self.shrinkAnimation() self?.shrinkAnimation()
} }
} }
} }
...@@ -137,12 +137,12 @@ public class MaterialPulseView : MaterialView { ...@@ -137,12 +137,12 @@ public class MaterialPulseView : MaterialView {
pulseLayer.hidden = false pulseLayer.hidden = false
} }
pulseLayer.addAnimation(MaterialAnimation.scale(3 * d, duration: t), forKey: nil) pulseLayer.addAnimation(MaterialAnimation.scale(3 * d, duration: t), forKey: nil)
MaterialAnimation.delay(t) { [unowned self] in MaterialAnimation.delay(t) { [weak self] in
if nil != self.pulseColor && 0 < self.pulseColorOpacity { if nil != self && nil != self!.pulseColor && 0 < self!.pulseColorOpacity {
MaterialAnimation.animateWithDuration(t, animations: { MaterialAnimation.animateWithDuration(t, animations: {
pulseLayer.hidden = true pulseLayer.hidden = true
}) { }) {
pulseLayer.removeFromSuperlayer() pulseLayer.removeFromSuperlayer()
} }
} }
} }
......
...@@ -42,7 +42,7 @@ public enum MaterialSwitchState { ...@@ -42,7 +42,7 @@ public enum MaterialSwitchState {
public enum MaterialSwitchSize { public enum MaterialSwitchSize {
case Small case Small
case Normal case Default
case Large case Large
} }
...@@ -195,14 +195,14 @@ public class MaterialSwitch: UIControl { ...@@ -195,14 +195,14 @@ public class MaterialSwitch: UIControl {
} }
/// MaterialSwitch size. /// MaterialSwitch size.
public var switchSize: MaterialSwitchSize = .Normal { public var switchSize: MaterialSwitchSize = .Default {
didSet { didSet {
switch switchSize { switch switchSize {
case .Small: case .Small:
trackThickness = 13 trackThickness = 13
buttonDiameter = 18 buttonDiameter = 18
frame = CGRectMake(0, 0, 30, 25) frame = CGRectMake(0, 0, 30, 25)
case .Normal: case .Default:
trackThickness = 17 trackThickness = 17
buttonDiameter = 24 buttonDiameter = 24
frame = CGRectMake(0, 0, 40, 30) frame = CGRectMake(0, 0, 40, 30)
...@@ -236,7 +236,7 @@ public class MaterialSwitch: UIControl { ...@@ -236,7 +236,7 @@ public class MaterialSwitch: UIControl {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareTrack() prepareTrack()
prepareButton() prepareButton()
prepareSwitchSize(.Normal) prepareSwitchSize(.Default)
prepareSwitchStyle(.Light) prepareSwitchStyle(.Light)
prepareSwitchState(.Off) prepareSwitchState(.Off)
} }
...@@ -247,7 +247,7 @@ public class MaterialSwitch: UIControl { ...@@ -247,7 +247,7 @@ public class MaterialSwitch: UIControl {
- Parameter style: A MaterialSwitchStyle value. - Parameter style: A MaterialSwitchStyle value.
- Parameter size: A MaterialSwitchSize value. - Parameter size: A MaterialSwitchSize value.
*/ */
public init(state: MaterialSwitchState = .On, style: MaterialSwitchStyle = .Light, size: MaterialSwitchSize = .Normal) { public init(state: MaterialSwitchState = .On, style: MaterialSwitchStyle = .Light, size: MaterialSwitchSize = .Default) {
track = MaterialView(frame: CGRectZero) track = MaterialView(frame: CGRectZero)
button = FabButton(frame: CGRectZero) button = FabButton(frame: CGRectZero)
super.init(frame: CGRectZero) super.init(frame: CGRectZero)
...@@ -267,7 +267,7 @@ public class MaterialSwitch: UIControl { ...@@ -267,7 +267,7 @@ public class MaterialSwitch: UIControl {
switch switchSize { switch switchSize {
case .Small: case .Small:
return CGSizeMake(30, 25) return CGSizeMake(30, 25)
case .Normal: case .Default:
return CGSizeMake(40, 30) return CGSizeMake(40, 30)
case .Large: case .Large:
return CGSizeMake(50, 40) return CGSizeMake(50, 40)
...@@ -456,7 +456,7 @@ public class MaterialSwitch: UIControl { ...@@ -456,7 +456,7 @@ public class MaterialSwitch: UIControl {
switch switchSize { switch switchSize {
case .Small: case .Small:
w = 30 w = 30
case .Normal: case .Default:
w = 40 w = 40
case .Large: case .Large:
w = 50 w = 50
......
...@@ -336,7 +336,7 @@ public class MaterialView : UIView { ...@@ -336,7 +336,7 @@ public class MaterialView : UIView {
prepareView() prepareView()
} }
/// A convenience initializer that is mostly used with AutoLayout. /// A convenience initializer.
public convenience init() { public convenience init() {
self.init(frame: CGRectNull) self.init(frame: CGRectNull)
} }
......
...@@ -34,74 +34,41 @@ public class NavigationBarView : MaterialView { ...@@ -34,74 +34,41 @@ public class NavigationBarView : MaterialView {
/// TitleView that holds the titleLabel and detailLabel. /// TitleView that holds the titleLabel and detailLabel.
public private(set) lazy var titleView: MaterialView = MaterialView() public private(set) lazy var titleView: MaterialView = MaterialView()
/** /// Device status bar style.
:name: statusBarStyle
*/
public var statusBarStyle: UIStatusBarStyle = UIApplication.sharedApplication().statusBarStyle { public var statusBarStyle: UIStatusBarStyle = UIApplication.sharedApplication().statusBarStyle {
didSet { didSet {
UIApplication.sharedApplication().statusBarStyle = statusBarStyle UIApplication.sharedApplication().statusBarStyle = statusBarStyle
} }
} }
/** /// Title label.
:name: contentInsets
*/
public var contentInsetPreset: MaterialEdgeInset = .None {
didSet {
contentInset = MaterialEdgeInsetToValue(contentInsetPreset)
}
}
/**
:name: contentInset
*/
public var contentInset: UIEdgeInsets = MaterialEdgeInsetToValue(.Square2) {
didSet {
reloadView()
}
}
/**
:name: titleLabel
*/
public var titleLabel: UILabel? { public var titleLabel: UILabel? {
didSet { didSet {
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
v.grid.rows = nil == detailLabel ? 3 : 2
titleView.addSubview(v) titleView.addSubview(v)
} }
reloadView() reloadView()
} }
} }
/** /// Detail label.
:name: detailLabel
*/
public var detailLabel: UILabel? { public var detailLabel: UILabel? {
didSet { didSet {
if let v: UILabel = detailLabel { if let v: UILabel = detailLabel {
v.grid.rows = 1
titleView.addSubview(v) titleView.addSubview(v)
titleLabel?.grid.rows = 2
} else {
titleLabel?.grid.rows = 3
} }
reloadView() reloadView()
} }
} }
/** /// Left side UIControls.
:name: leftControls
*/
public var leftControls: Array<UIControl>? { public var leftControls: Array<UIControl>? {
didSet { didSet {
reloadView() reloadView()
} }
} }
/** /// Right side UIControls.
:name: rightControls
*/
public var rightControls: Array<UIControl>? { public var rightControls: Array<UIControl>? {
didSet { didSet {
reloadView() reloadView()
...@@ -109,36 +76,74 @@ public class NavigationBarView : MaterialView { ...@@ -109,36 +76,74 @@ public class NavigationBarView : MaterialView {
} }
/** /**
:name: init An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
} }
/** /**
:name: init An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
} }
/** /// A convenience initializer.
:name: init
*/
public convenience init() { public convenience init() {
self.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 70)) self.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 64))
} }
/** /**
:name: init 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 convenience init?(titleLabel: UILabel? = nil, detailLabel: UILabel? = nil, leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) { public convenience init?(titleLabel: UILabel? = nil, detailLabel: UILabel? = nil, leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) {
self.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 70)) self.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 64))
prepareProperties(titleLabel, detailLabel: detailLabel, leftControls: leftControls, rightControls: rightControls) prepareProperties(titleLabel, detailLabel: detailLabel, leftControls: leftControls, rightControls: rightControls)
} }
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
// General alignment.
switch UIDevice.currentDevice().orientation {
case .LandscapeLeft, .LandscapeRight:
grid.contentInset.top = 0
grid.contentInset.bottom = 0
titleView.grid.spacing = 2
titleView.grid.contentInset.top = 4
titleView.grid.contentInset.bottom = 8
height = 44
default:
grid.contentInset.top = 20
grid.contentInset.bottom = 8
titleView.grid.spacing = 0
titleView.grid.contentInset.top = 0
titleView.grid.contentInset.bottom = 0
height = 64
}
// TitleView alignment.
titleView.grid.axis.rows = 6
if let v: UILabel = titleLabel {
titleView.grid.views?.append(v)
v.grid.rows = nil == detailLabel ? 6 : 4
}
if let v: UILabel = detailLabel {
titleView.grid.views?.append(v)
v.grid.rows = 2
}
width = UIScreen.mainScreen().bounds.width
grid.axis.columns = Int(width / 48)
reloadView() reloadView()
} }
...@@ -147,9 +152,11 @@ public class NavigationBarView : MaterialView { ...@@ -147,9 +152,11 @@ public class NavigationBarView : MaterialView {
reloadView() reloadView()
} }
/** public override func intrinsicContentSize() -> CGSize {
:name: reloadView return CGSizeMake(UIScreen.mainScreen().bounds.width, 64)
*/ }
/// Reloads the view.
public func reloadView() { public func reloadView() {
layoutIfNeeded() layoutIfNeeded()
...@@ -162,7 +169,7 @@ public class NavigationBarView : MaterialView { ...@@ -162,7 +169,7 @@ public class NavigationBarView : MaterialView {
} }
// Size of single grid column. // Size of single grid column.
let g: CGFloat = width / CGFloat(0 < grid.columns ? grid.columns : 1) let g: CGFloat = width / CGFloat(0 < grid.axis.columns ? grid.axis.columns : 1)
grid.views = [] grid.views = []
titleView.grid.columns = grid.axis.columns titleView.grid.columns = grid.axis.columns
...@@ -206,6 +213,7 @@ public class NavigationBarView : MaterialView { ...@@ -206,6 +213,7 @@ public class NavigationBarView : MaterialView {
grid.reloadLayout() grid.reloadLayout()
titleView.grid.views = [] titleView.grid.views = []
titleView.grid.axis.rows = 6
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
titleView.grid.views?.append(v) titleView.grid.views?.append(v)
} }
...@@ -216,32 +224,38 @@ public class NavigationBarView : MaterialView { ...@@ -216,32 +224,38 @@ public class NavigationBarView : MaterialView {
} }
/** /**
:name: prepareView 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() { public override func prepareView() {
super.prepareView() super.prepareView()
grid.spacing = 10 grid.spacing = 8
grid.axis.columns = 8
grid.axis.inherited = false grid.axis.inherited = false
grid.contentInset.top = 25 grid.contentInset.top = 20
grid.contentInset.left = 10 grid.contentInset.left = 8
grid.contentInset.bottom = 10 grid.contentInset.bottom = 8
grid.contentInset.right = 10 grid.contentInset.right = 8
depth = .Depth1 depth = .Depth1
prepareTextView() prepareTitleView()
} }
public func prepareTextView() { /// Prepares the titleView.
public func prepareTitleView() {
titleView.backgroundColor = nil titleView.backgroundColor = nil
titleView.grid.spacing = 4
titleView.grid.axis.rows = 3
titleView.grid.axis.inherited = false titleView.grid.axis.inherited = false
titleView.grid.axis.direction = .Vertical titleView.grid.axis.direction = .Vertical
addSubview(titleView) addSubview(titleView)
} }
/** /**
:name: prepareProperties 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.
*/ */
internal func prepareProperties(titleLabel: UILabel?, detailLabel: UILabel?, leftControls: Array<UIControl>?, rightControls: Array<UIControl>?) { internal func prepareProperties(titleLabel: UILabel?, detailLabel: UILabel?, leftControls: Array<UIControl>?, rightControls: Array<UIControl>?) {
self.titleLabel = titleLabel self.titleLabel = titleLabel
......
...@@ -362,7 +362,7 @@ public class TextField : UITextField { ...@@ -362,7 +362,7 @@ public class TextField : UITextField {
prepareView() prepareView()
} }
/// A convenience initializer that is mostly used with AutoLayout. /// A convenience initializer.
public convenience init() { public convenience init() {
self.init(frame: CGRectNull) self.init(frame: CGRectNull)
} }
......
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