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