Commit 1781bc34 by Daniel Dahan

updated projects to reflect changes to the dynamic sizing of Toolbars and SearchBars

parent 7646c696
...@@ -38,12 +38,16 @@ import UIKit ...@@ -38,12 +38,16 @@ import UIKit
import Material import Material
class ViewController: UIViewController { class ViewController: UIViewController {
/// Reference for containerView.
private var containerView: UIView!
/// Reference for SearchBar. /// Reference for SearchBar.
private var searchBar: SearchBar = SearchBar() private var searchBar: SearchBar!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareContainerView()
prepareSearchBar() prepareSearchBar()
} }
...@@ -52,22 +56,22 @@ class ViewController: UIViewController { ...@@ -52,22 +56,22 @@ class ViewController: UIViewController {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
} }
/// Prepare toolbar. /// Prepares the containerView.
private func prepareSearchBar() { private func prepareContainerView() {
var image: UIImage? = MaterialIcon.cm.arrowBack containerView = UIView()
view.addSubview(containerView)
// Back button. MaterialLayout.alignToParent(view, child: containerView, top: 100, left: 20, right: 20)
let backButton: IconButton = IconButton() }
backButton.pulseColor = MaterialColor.grey.base
backButton.tintColor = MaterialColor.grey.darken4 /// Prepares the toolbar
backButton.setImage(image, forState: .Normal) private func prepareSearchBar() {
backButton.setImage(image, forState: .Highlighted) searchBar = SearchBar()
containerView.addSubview(searchBar)
// Switch control. let image: UIImage? = MaterialIcon.cm.moreVertical
let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .Default, size: .Small)
// More button. // More button.
image = MaterialIcon.cm.moreHorizontal
let moreButton: IconButton = IconButton() let moreButton: IconButton = IconButton()
moreButton.pulseColor = MaterialColor.grey.base moreButton.pulseColor = MaterialColor.grey.base
moreButton.tintColor = MaterialColor.grey.darken4 moreButton.tintColor = MaterialColor.grey.darken4
...@@ -79,10 +83,6 @@ class ViewController: UIViewController { ...@@ -79,10 +83,6 @@ class ViewController: UIViewController {
"View controller-based status bar appearance = NO" "View controller-based status bar appearance = NO"
to your info.plist file and set the following property. to your info.plist file and set the following property.
*/ */
searchBar.statusBarStyle = .Default searchBar.leftControls = [moreButton]
searchBar.leftControls = [backButton]
searchBar.rightControls = [switchControl, moreButton]
view.addSubview(searchBar)
} }
} }
...@@ -37,16 +37,10 @@ import UIKit ...@@ -37,16 +37,10 @@ import UIKit
import Material import Material
class AppSearchBarController: SearchBarController { class AppSearchBarController: SearchBarController {
override func viewDidLoad() { /// Prepares the view.
super.viewDidLoad()
prepareView()
prepareSearchBar()
}
/// Prepares view.
override func prepareView() { override func prepareView() {
super.prepareView() super.prepareView()
view.backgroundColor = MaterialColor.black prepareSearchBar()
} }
/// Prepares the searchBar. /// Prepares the searchBar.
......
...@@ -102,7 +102,6 @@ class ViewController: UIViewController { ...@@ -102,7 +102,6 @@ class ViewController: UIViewController {
"View controller-based status bar appearance = NO" "View controller-based status bar appearance = NO"
to your info.plist file and set the following property. to your info.plist file and set the following property.
*/ */
toolbar.statusBarStyle = .LightContent
toolbar.backgroundColor = MaterialColor.blue.base toolbar.backgroundColor = MaterialColor.blue.base
toolbar.leftControls = [menuButton] toolbar.leftControls = [menuButton]
toolbar.rightControls = [switchControl, searchButton] toolbar.rightControls = [switchControl, searchButton]
......
...@@ -37,20 +37,9 @@ import UIKit ...@@ -37,20 +37,9 @@ import UIKit
import Material import Material
class AppToolbarController: ToolbarController { class AppToolbarController: ToolbarController {
override func viewWillAppear(animated: Bool) { /// Prepares the view.
super.viewWillAppear(animated)
/*
To lighten the status bar - add the
"View controller-based status bar appearance = NO"
to your info.plist file and set the following property.
*/
toolbar.statusBarStyle = .LightContent
}
/// Prepares view.
override func prepareView() { override func prepareView() {
super.prepareView() super.prepareView()
view.backgroundColor = MaterialColor.black
prepareToolbar() prepareToolbar()
} }
...@@ -92,10 +81,12 @@ class AppToolbarController: ToolbarController { ...@@ -92,10 +81,12 @@ class AppToolbarController: ToolbarController {
image = MaterialIcon.cm.search image = MaterialIcon.cm.search
let searchButton: IconButton = IconButton() let searchButton: IconButton = IconButton()
searchButton.tintColor = MaterialColor.white searchButton.tintColor = MaterialColor.white
searchButton.pulseColor = MaterialColor.white
searchButton.setImage(image, forState: .Normal) searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted) searchButton.setImage(image, forState: .Highlighted)
searchButton.addTarget(self, action: #selector(handleSearchButton), forControlEvents: .TouchUpInside) searchButton.addTarget(self, action: #selector(handleSearchButton), forControlEvents: .TouchUpInside)
toolbar.statusBarStyle = .LightContent
toolbar.leftControls = [menuButton] toolbar.leftControls = [menuButton]
toolbar.rightControls = [switchControl, searchButton] toolbar.rightControls = [switchControl, searchButton]
toolbar.backgroundColor = MaterialColor.blue.base toolbar.backgroundColor = MaterialColor.blue.base
......
...@@ -50,17 +50,8 @@ class ViewController: UIViewController { ...@@ -50,17 +50,8 @@ class ViewController: UIViewController {
/// Adjusts the Toolbar height to the correct height based on the orientation value. /// Adjusts the Toolbar height to the correct height based on the orientation value.
private func adjustToOrientation(toInterfaceOrientation: UIInterfaceOrientation) { private func adjustToOrientation(toInterfaceOrientation: UIInterfaceOrientation) {
// If landscape. toolbar.contentInset.top = .iPad == MaterialDevice.type || UIInterfaceOrientationIsPortrait(toInterfaceOrientation) ? 20 : 4
if UIInterfaceOrientationIsLandscape(toInterfaceOrientation) { toolbarHeightConstraint?.constant = toolbar.intrinsicContentSize().height
/**
The height of the Toolbar is dependant on the device being used.
If the device is an iPad, the height should stay the same as in Portrait
view, otherwise it should strink to the Landscape height for iPhone.
*/
toolbarHeightConstraint?.constant = .iPad == MaterialDevice.type ? toolbar!.heightForPortraitOrientation : toolbar!.heightForLandscapeOrientation
} else {
toolbarHeightConstraint?.constant = toolbar!.heightForPortraitOrientation
}
} }
/// General preparation statements. /// General preparation statements.
......
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Material' s.name = 'Material'
s.version = '1.41.1' s.version = '1.41.2'
s.license = 'BSD' 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'
s.social_media_url = 'https://www.facebook.com/graphkit' s.social_media_url = 'https://www.facebook.com/graphkit'
......
...@@ -428,13 +428,13 @@ ...@@ -428,13 +428,13 @@
96BCB7991CB40DC500C806FE /* BarViewController.swift */, 96BCB7991CB40DC500C806FE /* BarViewController.swift */,
96BCB7951CB40DC500C806FE /* SearchBar.swift */, 96BCB7951CB40DC500C806FE /* SearchBar.swift */,
96BCB7961CB40DC500C806FE /* SearchBarController.swift */, 96BCB7961CB40DC500C806FE /* SearchBarController.swift */,
96BCB79F1CB40DC500C806FE /* Toolbar.swift */,
96BCB7A01CB40DC500C806FE /* ToolbarController.swift */,
96BCB7971CB40DC500C806FE /* SideNavigationController.swift */, 96BCB7971CB40DC500C806FE /* SideNavigationController.swift */,
96BCB78D1CB40DC500C806FE /* Menu.swift */, 96BCB78D1CB40DC500C806FE /* Menu.swift */,
96BCB78E1CB40DC500C806FE /* MenuView.swift */, 96BCB78E1CB40DC500C806FE /* MenuView.swift */,
96BCB78F1CB40DC500C806FE /* MenuViewController.swift */, 96BCB78F1CB40DC500C806FE /* MenuViewController.swift */,
96BCB79A1CB40DC500C806FE /* TabBar.swift */, 96BCB79A1CB40DC500C806FE /* TabBar.swift */,
96BCB79F1CB40DC500C806FE /* Toolbar.swift */,
96BCB7A01CB40DC500C806FE /* ToolbarController.swift */,
96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */, 96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */,
96BCB7591CB40DC500C806FE /* BottomTabBar.swift */, 96BCB7591CB40DC500C806FE /* BottomTabBar.swift */,
96BCB7901CB40DC500C806FE /* NavigationBar.swift */, 96BCB7901CB40DC500C806FE /* NavigationBar.swift */,
......
...@@ -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.41.1</string> <string>1.41.2</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -56,10 +56,6 @@ public class BarView : ControlView { ...@@ -56,10 +56,6 @@ public class BarView : ControlView {
prepareProperties(leftControls, rightControls: rightControls) prepareProperties(leftControls, rightControls: rightControls)
} }
public override func intrinsicContentSize() -> CGSize {
return CGSizeMake(width, 44 + contentInset.top + contentInset.bottom)
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method it is recommended to override the prepareView method
......
...@@ -144,10 +144,7 @@ public class ControlView : MaterialView { ...@@ -144,10 +144,7 @@ public class ControlView : MaterialView {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { if willRenderView {
layoutIfNeeded() layoutIfNeeded()
frame.size.height = intrinsicContentSize().height
if 0 == frame.size.height {
frame.size.height = intrinsicContentSize().height
}
let factor: CGFloat = 24 let factor: CGFloat = 24
if let g: Int = Int(width / factor) { if let g: Int = Int(width / factor) {
...@@ -202,6 +199,10 @@ public class ControlView : MaterialView { ...@@ -202,6 +199,10 @@ public class ControlView : MaterialView {
} }
} }
public override func intrinsicContentSize() -> CGSize {
return CGSizeMake(width, 36 + contentInset.top + contentInset.bottom)
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method it is recommended to override the prepareView method
......
...@@ -71,16 +71,16 @@ public class SearchBar : BarView { ...@@ -71,16 +71,16 @@ public class SearchBar : BarView {
@IBInspectable public var placeholder: String? { @IBInspectable public var placeholder: String? {
didSet { didSet {
if let v: String = placeholder { if let v: String = placeholder {
textField.attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor]) textField.attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
} }
} }
} }
/// Placeholder textColor. /// Placeholder textColor.
@IBInspectable public var placeholderTextColor: UIColor = MaterialColor.darkText.others { @IBInspectable public var placeholderColor: UIColor = MaterialColor.darkText.others {
didSet { didSet {
if let v: String = placeholder { if let v: String = placeholder {
textField.attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor]) textField.attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
} }
} }
} }
...@@ -111,18 +111,24 @@ public class SearchBar : BarView { ...@@ -111,18 +111,24 @@ public class SearchBar : BarView {
prepareClearButton() prepareClearButton()
} }
/// Layout the clearButton.
public func layoutClearButton() {
let h: CGFloat = textField.frame.height
clearButton.frame = CGRectMake(textField.frame.width - h, 0, h, h)
}
/// Clears the textField text. /// Clears the textField text.
internal func handleClearButton() { internal func handleClearButton() {
textField.text = "" textField.text = nil
} }
/// Prepares the textField. /// Prepares the textField.
private func prepareTextField() { private func prepareTextField() {
textField = UITextField() textField = UITextField()
textField.font = RobotoFont.regularWithSize(20) textField.font = RobotoFont.regularWithSize(17)
textField.backgroundColor = MaterialColor.clear textField.backgroundColor = MaterialColor.clear
textField.clearButtonMode = .WhileEditing textField.clearButtonMode = .WhileEditing
tintColor = placeholderTextColor tintColor = placeholderColor
textColor = MaterialColor.darkText.primary textColor = MaterialColor.darkText.primary
placeholder = "Search" placeholder = "Search"
contentView.addSubview(textField) contentView.addSubview(textField)
...@@ -133,7 +139,7 @@ public class SearchBar : BarView { ...@@ -133,7 +139,7 @@ public class SearchBar : BarView {
let image: UIImage? = MaterialIcon.cm.close let image: UIImage? = MaterialIcon.cm.close
clearButton = IconButton() clearButton = IconButton()
clearButton.contentEdgeInsets = UIEdgeInsetsZero clearButton.contentEdgeInsets = UIEdgeInsetsZero
clearButton.tintColor = placeholderTextColor clearButton.tintColor = placeholderColor
clearButton.setImage(image, forState: .Normal) clearButton.setImage(image, forState: .Normal)
clearButton.setImage(image, forState: .Highlighted) clearButton.setImage(image, forState: .Highlighted)
clearButtonAutoHandleEnabled = true clearButtonAutoHandleEnabled = true
...@@ -141,10 +147,4 @@ public class SearchBar : BarView { ...@@ -141,10 +147,4 @@ public class SearchBar : BarView {
textField.rightViewMode = .WhileEditing textField.rightViewMode = .WhileEditing
textField.rightView = clearButton textField.rightView = clearButton
} }
/// Layout the clearButton.
private func layoutClearButton() {
let h: CGFloat = textField.frame.height
clearButton.frame = CGRectMake(textField.frame.width - h, 0, h, h)
}
} }
...@@ -50,7 +50,30 @@ public extension UIViewController { ...@@ -50,7 +50,30 @@ public extension UIViewController {
public class SearchBarController : BarViewController { public class SearchBarController : BarViewController {
/// Reference to the SearchBar. /// Reference to the SearchBar.
public private(set) lazy var searchBar: SearchBar = SearchBar() public private(set) var searchBar: SearchBar!
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layoutSubviews()
}
/// Layout subviews.
public func layoutSubviews() {
let w: CGFloat = MaterialDevice.width
let h: CGFloat = MaterialDevice.height
if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape {
searchBar.contentInset.top = 4
} else {
searchBar.contentInset.top = 24
}
searchBar.width = w
let p: CGFloat = searchBar.intrinsicContentSize().height
rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
...@@ -66,7 +89,10 @@ public class SearchBarController : BarViewController { ...@@ -66,7 +89,10 @@ public class SearchBarController : BarViewController {
/// Prepares the SearchBar. /// Prepares the SearchBar.
private func prepareSearchBar() { private func prepareSearchBar() {
searchBar.zPosition = 1000 if nil == searchBar {
view.addSubview(searchBar) searchBar = SearchBar()
searchBar.zPosition = 1000
view.addSubview(searchBar)
}
} }
} }
...@@ -69,7 +69,7 @@ public class ToolbarController : BarViewController { ...@@ -69,7 +69,7 @@ public class ToolbarController : BarViewController {
private var internalFloatingViewController: UIViewController? private var internalFloatingViewController: UIViewController?
/// Reference to the Toolbar. /// Reference to the Toolbar.
public private(set) lazy var toolbar: Toolbar = Toolbar() public private(set) var toolbar: Toolbar!
/// Delegation handler. /// Delegation handler.
public weak var delegate: ToolbarControllerDelegate? public weak var delegate: ToolbarControllerDelegate?
...@@ -144,36 +144,42 @@ public class ToolbarController : BarViewController { ...@@ -144,36 +144,42 @@ public class ToolbarController : BarViewController {
layoutSubviews() layoutSubviews()
} }
/**
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()
prepareToolbar()
}
/// Layout subviews. /// Layout subviews.
public func layoutSubviews() { public func layoutSubviews() {
let w: CGFloat = MaterialDevice.width
let h: CGFloat = MaterialDevice.height let h: CGFloat = MaterialDevice.height
if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape { if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape {
toolbar.contentInset.top = 24
} else {
toolbar.contentInset.top = 4 toolbar.contentInset.top = 4
} else {
toolbar.contentInset.top = 24
} }
toolbar.width = w
let p: CGFloat = toolbar.intrinsicContentSize().height let p: CGFloat = toolbar.intrinsicContentSize().height
rootViewController.view.frame.origin.y = p rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p rootViewController.view.frame.size.height = h - p
} }
/**
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()
prepareToolbar()
}
/// Prepares the Toolbar. /// Prepares the Toolbar.
private func prepareToolbar() { private func prepareToolbar() {
toolbar.zPosition = 1000 if nil == toolbar {
view.addSubview(toolbar) toolbar = Toolbar()
toolbar.zPosition = 1000
view.addSubview(toolbar)
}
} }
} }
\ 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