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 {
private func prepareNavigationItem() {
navigationItem.title = "Blue"
navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
}
}
......@@ -53,6 +53,5 @@ class GreenViewController: UIViewController {
private func prepareNavigationItem() {
navigationItem.title = "Green"
navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
}
}
......@@ -53,6 +53,5 @@ class OrangeViewController: UIViewController {
private func prepareNavigationItem() {
navigationItem.title = "Orange"
navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
}
}
......@@ -53,6 +53,5 @@ class PurpleViewController: UIViewController {
private func prepareNavigationItem() {
navigationItem.title = "Purple"
navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
}
}
......@@ -98,7 +98,8 @@ class YellowViewController: UIViewController {
private func prepareNavigationItem() {
navigationItem.title = "Yellow"
navigationItem.titleLabel.textAlignment = .Left
navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
navigationItem.detailLabel.textAlignment = .Left
navigationItem.leftControls = [menuButton]
navigationItem.rightControls = [switchControl, moreButton]
......
......@@ -44,8 +44,13 @@ class AppToolbarController: ToolbarController {
prepareToolbar()
}
/// Swaps rootViewControllers.
func handleMenuButton() {
transitionFromRootViewController(rootViewController.isKindOfClass(YellowViewController) ? GreenViewController() : YellowViewController())
}
/// Toggle NavigationDrawerController right UIViewController.
internal func handleSearchButton() {
func handleSearchButton() {
floatingViewController = GreenViewController()
MaterialAnimation.delay(1.5) { [weak self] in
......@@ -60,11 +65,9 @@ class AppToolbarController: ToolbarController {
toolbar.title = "Material"
toolbar.titleLabel.textColor = MaterialColor.white
// Detail label. Uncomment the code below to use a detail label.
// toolbar.detailLabel.text = "Build Beautiful Software"
// toolbar.detailLabel.textAlignment = .Left
// toolbar.detailLabel.textColor = MaterialColor.white
// toolbar.detailLabel.font = RobotoFont.regular
toolbar.detail = "Build Beautiful Software"
toolbar.detailLabel.textAlignment = .Left
toolbar.detailLabel.textColor = MaterialColor.white
var image: UIImage? = MaterialIcon.cm.menu
......@@ -74,6 +77,7 @@ class AppToolbarController: ToolbarController {
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)
......
Pod::Spec.new do |s|
s.name = 'Material'
s.version = '1.42.1'
s.version = '1.42.2'
s.license = 'BSD-3-Clause'
s.summary = 'An animation and graphics framework for Material Design in Swift.'
s.homepage = 'http://cosmicmind.io'
......
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.42.1</string>
<string>1.42.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -69,7 +69,6 @@ public class BottomNavigationController : UITabBarController, UITabBarController
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
......@@ -79,7 +78,6 @@ public class BottomNavigationController : UITabBarController, UITabBarController
*/
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
prepareView()
}
public init() {
......
......@@ -184,7 +184,6 @@ public class BottomTabBar : UITabBar {
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
......
......@@ -126,7 +126,6 @@ public class ControlView : MaterialView {
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
......@@ -137,14 +136,12 @@ public class ControlView : MaterialView {
*/
public override init(frame: CGRect) {
super.init(frame: frame)
prepareView()
}
/// Basic initializer.
public init() {
super.init(frame: CGRectZero)
frame.size = intrinsicContentSize()
prepareView()
}
/**
......@@ -155,7 +152,6 @@ public class ControlView : MaterialView {
public init(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) {
super.init(frame: CGRectZero)
frame.size = intrinsicContentSize()
prepareView()
prepareProperties(leftControls, rightControls: rightControls)
}
......
......@@ -318,7 +318,6 @@ public class MaterialButton : UIButton {
public required init?(coder aDecoder: NSCoder) {
contentEdgeInsetsPreset = .None
super.init(coder: aDecoder)
prepareView()
}
/**
......
......@@ -420,7 +420,6 @@ public class MaterialCollectionReusableView : UICollectionReusableView {
shape = .None
contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder)
prepareView()
}
/**
......
......@@ -420,7 +420,6 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
shape = .None
contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder)
prepareView()
}
/**
......
......@@ -133,7 +133,6 @@ public class MaterialLabel : UILabel {
*/
public convenience init() {
self.init(frame: CGRectZero)
prepareView()
}
/**
......
......@@ -281,7 +281,6 @@ public class MaterialTableViewCell : UITableViewCell {
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
......
......@@ -364,7 +364,6 @@ public class MaterialView : UIView {
public required init?(coder aDecoder: NSCoder) {
contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder)
prepareView()
}
/**
......
......@@ -268,7 +268,6 @@ public class NavigationBar : UINavigationBar {
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
......@@ -380,37 +379,40 @@ public class NavigationBar : UINavigationBar {
titleView.grid.reloadLayout()
// contentView alignment.
if let titleLabel: UILabel = item.titleLabel {
if let _: String = titleLabel.text {
if nil == titleLabel.superview {
contentView.addSubview(titleLabel)
}
if let detailLabel: UILabel = item.detailLabel {
if let _: String = detailLabel.text {
if nil == detailLabel.superview {
contentView.addSubview(detailLabel)
}
titleLabel.sizeToFit()
detailLabel.sizeToFit()
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 {
detailLabel.removeFromSuperview()
titleLabel.frame = contentView.bounds
}
}
if nil != item.title && "" != item.title {
if nil == item.titleLabel.superview {
contentView.addSubview(item.titleLabel)
}
item.titleLabel.frame = contentView.bounds
} else {
item.titleLabel.removeFromSuperview()
}
if nil != item.detail && "" != item.detail {
if nil == item.detailLabel.superview {
contentView.addSubview(item.detailLabel)
}
if nil == item.titleLabel.superview {
item.detailLabel.frame = contentView.bounds
} else {
titleLabel.removeFromSuperview()
contentView.grid.reloadLayout()
item.titleLabel.sizeToFit()
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
}
/**
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
active left UIViewController.
*/
......@@ -348,7 +357,15 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
*/
public required init?(coder aDecoder: NSCoder) {
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
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.
public override func layoutSubviews() {
if opened {
......@@ -834,17 +865,13 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
}
}
/**
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()
prepareLeftView()
prepareRightView()
/// Prepares the contentViewController.
private func prepareContentViewController() {
if nil == contentViewController {
contentViewController = UIViewController()
contentViewController!.view.backgroundColor = MaterialColor.black
}
prepareViewControllerWithinContainer(contentViewController, container: view)
}
/// A method that prepares the leftViewController.
......@@ -869,7 +896,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
enabledLeftView = false
enabledLeftPanGesture = false
enabledLeftTapGesture = false
} else {
} else if nil == leftView {
leftViewWidth = .iPhone == MaterialDevice.type ? 280 : 320
leftView = MaterialView()
leftView!.frame = CGRectMake(0, 0, leftViewWidth, view.frame.height)
......@@ -889,7 +916,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
enabledRightView = false
enabledRightPanGesture = false
enabledRightTapGesture = false
} else {
} else if nil == rightView {
rightViewWidth = .iPhone == MaterialDevice.type ? 280 : 320
rightView = MaterialView()
rightView!.frame = CGRectMake(0, 0, rightViewWidth, view.frame.height)
......
......@@ -61,7 +61,7 @@ public class RootController : UIViewController {
is recommended to use the transitionFromRootViewController
helper method.
*/
public private(set) var rootViewController: UIViewController!
public internal(set) var rootViewController: UIViewController!
/**
An initializer that initializes the object with a NSCoder object.
......@@ -69,7 +69,6 @@ public class RootController : UIViewController {
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
......@@ -79,7 +78,6 @@ public class RootController : UIViewController {
*/
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
prepareView()
}
/**
......
......@@ -72,7 +72,6 @@ public class StatusBarController : RootController {
when subclassing.
*/
public override func prepareView() {
super.prepareView()
prepareStatusBarView()
}
......
......@@ -338,7 +338,6 @@ public class TextField : UITextField {
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
......
......@@ -305,7 +305,6 @@ public class TextView: UITextView {
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
......
......@@ -62,19 +62,41 @@ public class Toolbar : BarView {
public override func layoutSubviews() {
super.layoutSubviews()
if willRenderView {
if let _: String = detail {
titleLabel.sizeToFit()
detailLabel.sizeToFit()
if nil != title && "" != title {
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
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
if nil == titleLabel.superview {
detailLabel.frame = contentView.bounds
} else {
titleLabel.sizeToFit()
detailLabel.sizeToFit()
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 {
titleLabel.frame = contentView.bounds
detailLabel.removeFromSuperview()
}
contentView.grid.reloadLayout()
}
}
......@@ -124,7 +146,6 @@ public class Toolbar : BarView {
titleLabel.contentScaleFactor = MaterialDevice.scale
titleLabel.font = RobotoFont.mediumWithSize(17)
titleLabel.textAlignment = .Left
contentView.addSubview(titleLabel)
}
/// Prepares the detailLabel.
......@@ -133,6 +154,5 @@ public class Toolbar : BarView {
detailLabel.contentScaleFactor = MaterialDevice.scale
detailLabel.font = RobotoFont.regularWithSize(12)
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