Commit aa98b4dc by Daniel Dahan

issue-444 and issue-445 are now fixed, where title alignment is correct with…

issue-444 and issue-445 are now fixed, where title alignment is correct with detail property equaling nil or '', and fixed crash where transitioning NavigationDrawerController rootViewController.
parent b2580b70
...@@ -53,6 +53,5 @@ class BlueViewController: UIViewController { ...@@ -53,6 +53,5 @@ class BlueViewController: UIViewController {
private func prepareNavigationItem() { private func prepareNavigationItem() {
navigationItem.title = "Blue" navigationItem.title = "Blue"
navigationItem.titleLabel.textAlignment = .Left navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
} }
} }
...@@ -53,6 +53,5 @@ class GreenViewController: UIViewController { ...@@ -53,6 +53,5 @@ class GreenViewController: UIViewController {
private func prepareNavigationItem() { private func prepareNavigationItem() {
navigationItem.title = "Green" navigationItem.title = "Green"
navigationItem.titleLabel.textAlignment = .Left navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
} }
} }
...@@ -53,6 +53,5 @@ class OrangeViewController: UIViewController { ...@@ -53,6 +53,5 @@ class OrangeViewController: UIViewController {
private func prepareNavigationItem() { private func prepareNavigationItem() {
navigationItem.title = "Orange" navigationItem.title = "Orange"
navigationItem.titleLabel.textAlignment = .Left navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
} }
} }
...@@ -53,6 +53,5 @@ class PurpleViewController: UIViewController { ...@@ -53,6 +53,5 @@ class PurpleViewController: UIViewController {
private func prepareNavigationItem() { private func prepareNavigationItem() {
navigationItem.title = "Purple" navigationItem.title = "Purple"
navigationItem.titleLabel.textAlignment = .Left navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
} }
} }
...@@ -98,7 +98,8 @@ class YellowViewController: UIViewController { ...@@ -98,7 +98,8 @@ class YellowViewController: UIViewController {
private func prepareNavigationItem() { private func prepareNavigationItem() {
navigationItem.title = "Yellow" navigationItem.title = "Yellow"
navigationItem.titleLabel.textAlignment = .Left navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
navigationItem.detailLabel.textAlignment = .Left
navigationItem.leftControls = [menuButton] navigationItem.leftControls = [menuButton]
navigationItem.rightControls = [switchControl, moreButton] navigationItem.rightControls = [switchControl, moreButton]
......
...@@ -44,8 +44,13 @@ class AppToolbarController: ToolbarController { ...@@ -44,8 +44,13 @@ class AppToolbarController: ToolbarController {
prepareToolbar() prepareToolbar()
} }
/// Swaps rootViewControllers.
func handleMenuButton() {
transitionFromRootViewController(rootViewController.isKindOfClass(YellowViewController) ? GreenViewController() : YellowViewController())
}
/// Toggle NavigationDrawerController right UIViewController. /// Toggle NavigationDrawerController right UIViewController.
internal func handleSearchButton() { func handleSearchButton() {
floatingViewController = GreenViewController() floatingViewController = GreenViewController()
MaterialAnimation.delay(1.5) { [weak self] in MaterialAnimation.delay(1.5) { [weak self] in
...@@ -60,11 +65,9 @@ class AppToolbarController: ToolbarController { ...@@ -60,11 +65,9 @@ class AppToolbarController: ToolbarController {
toolbar.title = "Material" toolbar.title = "Material"
toolbar.titleLabel.textColor = MaterialColor.white toolbar.titleLabel.textColor = MaterialColor.white
// Detail label. Uncomment the code below to use a detail label. toolbar.detail = "Build Beautiful Software"
// toolbar.detailLabel.text = "Build Beautiful Software" toolbar.detailLabel.textAlignment = .Left
// toolbar.detailLabel.textAlignment = .Left toolbar.detailLabel.textColor = MaterialColor.white
// toolbar.detailLabel.textColor = MaterialColor.white
// toolbar.detailLabel.font = RobotoFont.regular
var image: UIImage? = MaterialIcon.cm.menu var image: UIImage? = MaterialIcon.cm.menu
...@@ -74,6 +77,7 @@ class AppToolbarController: ToolbarController { ...@@ -74,6 +77,7 @@ class AppToolbarController: ToolbarController {
menuButton.pulseColor = MaterialColor.white menuButton.pulseColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal) menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted) menuButton.setImage(image, forState: .Highlighted)
menuButton.addTarget(self, action: #selector(handleMenuButton), forControlEvents: .TouchUpInside)
// Switch control. // Switch control.
let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small) let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small)
......
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Material' s.name = 'Material'
s.version = '1.42.1' s.version = '1.42.2'
s.license = 'BSD-3-Clause' s.license = 'BSD-3-Clause'
s.summary = 'An animation and graphics framework for Material Design in Swift.' s.summary = 'An animation and graphics framework for Material Design in Swift.'
s.homepage = 'http://cosmicmind.io' s.homepage = 'http://cosmicmind.io'
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.42.1</string> <string>1.42.2</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -69,7 +69,6 @@ public class BottomNavigationController : UITabBarController, UITabBarController ...@@ -69,7 +69,6 @@ public class BottomNavigationController : UITabBarController, UITabBarController
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
...@@ -79,7 +78,6 @@ public class BottomNavigationController : UITabBarController, UITabBarController ...@@ -79,7 +78,6 @@ public class BottomNavigationController : UITabBarController, UITabBarController
*/ */
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
prepareView()
} }
public init() { public init() {
......
...@@ -184,7 +184,6 @@ public class BottomTabBar : UITabBar { ...@@ -184,7 +184,6 @@ public class BottomTabBar : UITabBar {
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
......
...@@ -126,7 +126,6 @@ public class ControlView : MaterialView { ...@@ -126,7 +126,6 @@ public class ControlView : MaterialView {
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
...@@ -137,14 +136,12 @@ public class ControlView : MaterialView { ...@@ -137,14 +136,12 @@ public class ControlView : MaterialView {
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
prepareView()
} }
/// Basic initializer. /// Basic initializer.
public init() { public init() {
super.init(frame: CGRectZero) super.init(frame: CGRectZero)
frame.size = intrinsicContentSize() frame.size = intrinsicContentSize()
prepareView()
} }
/** /**
...@@ -155,7 +152,6 @@ public class ControlView : MaterialView { ...@@ -155,7 +152,6 @@ public class ControlView : MaterialView {
public init(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) { public init(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) {
super.init(frame: CGRectZero) super.init(frame: CGRectZero)
frame.size = intrinsicContentSize() frame.size = intrinsicContentSize()
prepareView()
prepareProperties(leftControls, rightControls: rightControls) prepareProperties(leftControls, rightControls: rightControls)
} }
......
...@@ -318,7 +318,6 @@ public class MaterialButton : UIButton { ...@@ -318,7 +318,6 @@ public class MaterialButton : UIButton {
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentEdgeInsetsPreset = .None contentEdgeInsetsPreset = .None
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
......
...@@ -420,7 +420,6 @@ public class MaterialCollectionReusableView : UICollectionReusableView { ...@@ -420,7 +420,6 @@ public class MaterialCollectionReusableView : UICollectionReusableView {
shape = .None shape = .None
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
......
...@@ -420,7 +420,6 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -420,7 +420,6 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
shape = .None shape = .None
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
......
...@@ -133,7 +133,6 @@ public class MaterialLabel : UILabel { ...@@ -133,7 +133,6 @@ public class MaterialLabel : UILabel {
*/ */
public convenience init() { public convenience init() {
self.init(frame: CGRectZero) self.init(frame: CGRectZero)
prepareView()
} }
/** /**
......
...@@ -281,7 +281,6 @@ public class MaterialTableViewCell : UITableViewCell { ...@@ -281,7 +281,6 @@ public class MaterialTableViewCell : UITableViewCell {
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
......
...@@ -364,7 +364,6 @@ public class MaterialView : UIView { ...@@ -364,7 +364,6 @@ public class MaterialView : UIView {
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
......
...@@ -268,7 +268,6 @@ public class NavigationBar : UINavigationBar { ...@@ -268,7 +268,6 @@ public class NavigationBar : UINavigationBar {
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
...@@ -380,37 +379,40 @@ public class NavigationBar : UINavigationBar { ...@@ -380,37 +379,40 @@ public class NavigationBar : UINavigationBar {
titleView.grid.reloadLayout() titleView.grid.reloadLayout()
// contentView alignment. // contentView alignment.
if let titleLabel: UILabel = item.titleLabel { if nil != item.title && "" != item.title {
if let _: String = titleLabel.text { if nil == item.titleLabel.superview {
if nil == titleLabel.superview { contentView.addSubview(item.titleLabel)
contentView.addSubview(titleLabel) }
} item.titleLabel.frame = contentView.bounds
} else {
if let detailLabel: UILabel = item.detailLabel { item.titleLabel.removeFromSuperview()
if let _: String = detailLabel.text { }
if nil == detailLabel.superview {
contentView.addSubview(detailLabel) if nil != item.detail && "" != item.detail {
} if nil == item.detailLabel.superview {
contentView.addSubview(item.detailLabel)
titleLabel.sizeToFit() }
detailLabel.sizeToFit()
if nil == item.titleLabel.superview {
let diff: CGFloat = (contentView.frame.height - titleLabel.frame.height - detailLabel.frame.height) / 2 item.detailLabel.frame = contentView.bounds
titleLabel.frame.size.height += diff
titleLabel.frame.size.width = contentView.frame.width
detailLabel.frame.size.height += diff
detailLabel.frame.size.width = contentView.frame.width
detailLabel.frame.origin.y = titleLabel.frame.height
} else {
detailLabel.removeFromSuperview()
titleLabel.frame = contentView.bounds
}
}
} else { } else {
titleLabel.removeFromSuperview() item.titleLabel.sizeToFit()
contentView.grid.reloadLayout() item.detailLabel.sizeToFit()
let diff: CGFloat = (contentView.frame.height - item.titleLabel.frame.height - item.detailLabel.frame.height) / 2
item.titleLabel.frame.size.height += diff
item.titleLabel.frame.size.width = contentView.frame.width
item.detailLabel.frame.size.height += diff
item.detailLabel.frame.size.width = contentView.frame.width
item.detailLabel.frame.origin.y = item.titleLabel.frame.height
} }
} else {
item.detailLabel.removeFromSuperview()
} }
contentView.grid.reloadLayout()
} }
} }
} }
......
...@@ -319,6 +319,15 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel ...@@ -319,6 +319,15 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
} }
/** /**
Content view controller to encompase the entire component. This is
primarily used when the StatusBar is being hidden. The alpha value of
the rootViewController decreases, and shows the StatusBar. To avoid
this, and to add a hidden transition viewController for complex
situations, the contentViewController was added.
*/
public private(set) var contentViewController: UIViewController?
/**
A UIViewController property that references the A UIViewController property that references the
active left UIViewController. active left UIViewController.
*/ */
...@@ -348,7 +357,15 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel ...@@ -348,7 +357,15 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView() }
/**
An initializer that initializes the object with an Optional nib and bundle.
- Parameter nibNameOrNil: An Optional String for the nib.
- Parameter bundle: An Optional NSBundle where the nib is located.
*/
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
} }
/** /**
...@@ -364,6 +381,20 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel ...@@ -364,6 +381,20 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
prepareView() 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() {
super.prepareView()
prepareContentViewController()
prepareLeftView()
prepareRightView()
}
/// Layout subviews. /// Layout subviews.
public override func layoutSubviews() { public override func layoutSubviews() {
if opened { if opened {
...@@ -834,17 +865,13 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel ...@@ -834,17 +865,13 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
} }
} }
/** /// Prepares the contentViewController.
Prepares the view instance when intialized. When subclassing, private func prepareContentViewController() {
it is recommended to override the prepareView method if nil == contentViewController {
to initialize property values and other setup operations. contentViewController = UIViewController()
The super.prepareView method should always be called immediately contentViewController!.view.backgroundColor = MaterialColor.black
when subclassing. }
*/ prepareViewControllerWithinContainer(contentViewController, container: view)
public override func prepareView() {
super.prepareView()
prepareLeftView()
prepareRightView()
} }
/// A method that prepares the leftViewController. /// A method that prepares the leftViewController.
...@@ -869,7 +896,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel ...@@ -869,7 +896,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
enabledLeftView = false enabledLeftView = false
enabledLeftPanGesture = false enabledLeftPanGesture = false
enabledLeftTapGesture = false enabledLeftTapGesture = false
} else { } else if nil == leftView {
leftViewWidth = .iPhone == MaterialDevice.type ? 280 : 320 leftViewWidth = .iPhone == MaterialDevice.type ? 280 : 320
leftView = MaterialView() leftView = MaterialView()
leftView!.frame = CGRectMake(0, 0, leftViewWidth, view.frame.height) leftView!.frame = CGRectMake(0, 0, leftViewWidth, view.frame.height)
...@@ -889,7 +916,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel ...@@ -889,7 +916,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
enabledRightView = false enabledRightView = false
enabledRightPanGesture = false enabledRightPanGesture = false
enabledRightTapGesture = false enabledRightTapGesture = false
} else { } else if nil == rightView {
rightViewWidth = .iPhone == MaterialDevice.type ? 280 : 320 rightViewWidth = .iPhone == MaterialDevice.type ? 280 : 320
rightView = MaterialView() rightView = MaterialView()
rightView!.frame = CGRectMake(0, 0, rightViewWidth, view.frame.height) rightView!.frame = CGRectMake(0, 0, rightViewWidth, view.frame.height)
......
...@@ -61,7 +61,7 @@ public class RootController : UIViewController { ...@@ -61,7 +61,7 @@ public class RootController : UIViewController {
is recommended to use the transitionFromRootViewController is recommended to use the transitionFromRootViewController
helper method. helper method.
*/ */
public private(set) var rootViewController: UIViewController! public internal(set) var rootViewController: UIViewController!
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
...@@ -69,7 +69,6 @@ public class RootController : UIViewController { ...@@ -69,7 +69,6 @@ public class RootController : UIViewController {
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
...@@ -79,7 +78,6 @@ public class RootController : UIViewController { ...@@ -79,7 +78,6 @@ public class RootController : UIViewController {
*/ */
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
prepareView()
} }
/** /**
......
...@@ -72,7 +72,6 @@ public class StatusBarController : RootController { ...@@ -72,7 +72,6 @@ public class StatusBarController : RootController {
when subclassing. when subclassing.
*/ */
public override func prepareView() { public override func prepareView() {
super.prepareView()
prepareStatusBarView() prepareStatusBarView()
} }
......
...@@ -338,7 +338,6 @@ public class TextField : UITextField { ...@@ -338,7 +338,6 @@ public class TextField : UITextField {
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
......
...@@ -305,7 +305,6 @@ public class TextView: UITextView { ...@@ -305,7 +305,6 @@ public class TextView: UITextView {
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
......
...@@ -62,19 +62,41 @@ public class Toolbar : BarView { ...@@ -62,19 +62,41 @@ public class Toolbar : BarView {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { if willRenderView {
if let _: String = detail {
titleLabel.sizeToFit() if nil != title && "" != title {
detailLabel.sizeToFit() if nil == titleLabel.superview {
contentView.addSubview(titleLabel)
}
titleLabel.frame = contentView.bounds
} else {
titleLabel.removeFromSuperview()
}
if nil != detail && "" != detail {
if nil == detailLabel.superview {
contentView.addSubview(detailLabel)
}
let diff: CGFloat = (contentView.frame.height - titleLabel.frame.height - detailLabel.frame.height) / 2 if nil == titleLabel.superview {
titleLabel.frame.size.height += diff detailLabel.frame = contentView.bounds
titleLabel.frame.size.width = contentView.frame.width } else {
detailLabel.frame.size.height += diff titleLabel.sizeToFit()
detailLabel.frame.size.width = contentView.frame.width detailLabel.sizeToFit()
detailLabel.frame.origin.y = titleLabel.frame.height
let diff: CGFloat = (contentView.frame.height - titleLabel.frame.height - detailLabel.frame.height) / 2
titleLabel.frame.size.height += diff
titleLabel.frame.size.width = contentView.frame.width
detailLabel.frame.size.height += diff
detailLabel.frame.size.width = contentView.frame.width
detailLabel.frame.origin.y = titleLabel.frame.height
}
} else { } else {
titleLabel.frame = contentView.bounds detailLabel.removeFromSuperview()
} }
contentView.grid.reloadLayout()
} }
} }
...@@ -124,7 +146,6 @@ public class Toolbar : BarView { ...@@ -124,7 +146,6 @@ public class Toolbar : BarView {
titleLabel.contentScaleFactor = MaterialDevice.scale titleLabel.contentScaleFactor = MaterialDevice.scale
titleLabel.font = RobotoFont.mediumWithSize(17) titleLabel.font = RobotoFont.mediumWithSize(17)
titleLabel.textAlignment = .Left titleLabel.textAlignment = .Left
contentView.addSubview(titleLabel)
} }
/// Prepares the detailLabel. /// Prepares the detailLabel.
...@@ -133,6 +154,5 @@ public class Toolbar : BarView { ...@@ -133,6 +154,5 @@ public class Toolbar : BarView {
detailLabel.contentScaleFactor = MaterialDevice.scale detailLabel.contentScaleFactor = MaterialDevice.scale
detailLabel.font = RobotoFont.regularWithSize(12) detailLabel.font = RobotoFont.regularWithSize(12)
detailLabel.textAlignment = .Left detailLabel.textAlignment = .Left
contentView.addSubview(detailLabel)
} }
} }
\ 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