Commit ba7f21c2 by Daniel Dahan

updated SearchBarView

parent 3744a4a9
...@@ -38,10 +38,13 @@ import UIKit ...@@ -38,10 +38,13 @@ import UIKit
import Material import Material
class ViewController: UIViewController { class ViewController: UIViewController {
/// Reference for NavigationBarView.
private var navigationBarView: NavigationBarView = NavigationBarView()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareAlignTitleAndDetailLabelToLeftExample() prepareNavigationBarView()
} }
/// General preparation statements. /// General preparation statements.
...@@ -49,25 +52,14 @@ class ViewController: UIViewController { ...@@ -49,25 +52,14 @@ class ViewController: UIViewController {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
} }
/// Prepares a text alignment example. /// Prepares the navigationBarView
private func prepareAlignTitleAndDetailLabelToLeftExample() { private func prepareNavigationBarView() {
let navigationBarView: NavigationBarView = NavigationBarView()
navigationBarView.backgroundColor = MaterialColor.blue.base
/*
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. // Title label.
let titleLabel: UILabel = UILabel() let titleLabel: UILabel = UILabel()
titleLabel.text = "Material" titleLabel.text = "Material"
titleLabel.textAlignment = .Left titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(17) titleLabel.font = RobotoFont.regularWithSize(17)
navigationBarView.titleLabel = titleLabel
// Detail label. // Detail label.
let detailLabel: UILabel = UILabel() let detailLabel: UILabel = UILabel()
...@@ -75,31 +67,38 @@ class ViewController: UIViewController { ...@@ -75,31 +67,38 @@ class ViewController: UIViewController {
detailLabel.textAlignment = .Left detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regularWithSize(12) detailLabel.font = RobotoFont.regularWithSize(12)
navigationBarView.detailLabel = detailLabel
var image = UIImage(named: "ic_menu_white")
// Menu button. // Menu button.
let img1: UIImage? = UIImage(named: "ic_menu_white")
let menuButton: FlatButton = FlatButton() let menuButton: FlatButton = FlatButton()
menuButton.pulseColor = nil menuButton.pulseColor = nil
menuButton.pulseScale = false menuButton.pulseScale = false
menuButton.setImage(img1, forState: .Normal) menuButton.setImage(image, forState: .Normal)
menuButton.setImage(img1, forState: .Highlighted) menuButton.setImage(image, forState: .Highlighted)
// Star button. // Star button.
let switchControl: MaterialSwitch = MaterialSwitch(state: .On, style: .Light) let switchControl: MaterialSwitch = MaterialSwitch(state: .On, style: .Light)
// Search button. // Search button.
let img3: UIImage? = UIImage(named: "ic_search_white") image = UIImage(named: "ic_search_white")
let searchButton: FlatButton = FlatButton() let searchButton: FlatButton = FlatButton()
searchButton.pulseColor = nil searchButton.pulseColor = nil
searchButton.pulseScale = false searchButton.pulseScale = false
searchButton.setImage(img3, forState: .Normal) searchButton.setImage(image, forState: .Normal)
searchButton.setImage(img3, forState: .Highlighted) searchButton.setImage(image, forState: .Highlighted)
// Add controls to left side. /*
navigationBarView.leftControls = [menuButton] 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
// Add controls to right side. navigationBarView.backgroundColor = MaterialColor.blue.base
navigationBarView.titleLabel = titleLabel
navigationBarView.detailLabel = detailLabel
navigationBarView.leftControls = [menuButton]
navigationBarView.rightControls = [switchControl, searchButton] navigationBarView.rightControls = [switchControl, searchButton]
view.addSubview(navigationBarView) view.addSubview(navigationBarView)
......
...@@ -36,8 +36,8 @@ import UIKit ...@@ -36,8 +36,8 @@ import UIKit
import Material import Material
class ViewController: UIViewController { class ViewController: UIViewController {
/// Reference for NavigationBarView. /// Reference for SearchBarView.
private var searchBarView: SearchBarView = SearchBarView(frame: CGRectNull) private var searchBarView: SearchBarView = SearchBarView()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
...@@ -52,41 +52,46 @@ class ViewController: UIViewController { ...@@ -52,41 +52,46 @@ class ViewController: UIViewController {
/// Prepare navigationBarView. /// Prepare navigationBarView.
private func prepareSearchBarView() { private func prepareSearchBarView() {
searchBarView.statusBarStyle = .LightContent
searchBarView.backgroundColor = MaterialColor.blue.base
var image = UIImage(named: "ic_close_white") var image = UIImage(named: "ic_close_white")
let clearButton: FlatButton = FlatButton() let clearButton: FlatButton = FlatButton()
clearButton.pulseColor = MaterialColor.white clearButton.pulseColor = nil
clearButton.pulseScale = false
clearButton.setImage(image, forState: .Normal) clearButton.setImage(image, forState: .Normal)
clearButton.setImage(image, forState: .Highlighted) clearButton.setImage(image, forState: .Highlighted)
searchBarView.clearButton = clearButton
image = UIImage(named: "ic_menu_white") image = UIImage(named: "ic_menu_white")
let menuButton: FlatButton = FlatButton() let menuButton: FlatButton = FlatButton()
menuButton.pulseColor = MaterialColor.white menuButton.pulseColor = nil
menuButton.pulseScale = false
menuButton.setImage(image, forState: .Normal) menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted) menuButton.setImage(image, forState: .Highlighted)
image = UIImage(named: "ic_search_white") image = UIImage(named: "ic_search_white")
let searchButton: FlatButton = FlatButton() let searchButton: FlatButton = FlatButton()
searchButton.pulseColor = MaterialColor.white searchButton.pulseColor = nil
searchButton.pulseScale = false
searchButton.setImage(image, forState: .Normal) searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted) searchButton.setImage(image, forState: .Highlighted)
/*
To lighten the status bar - add the
"View controller-based status bar appearance = NO"
to your info.plist file and set the following property.
*/
searchBarView.statusBarStyle = .LightContent
searchBarView.backgroundColor = MaterialColor.blue.base
searchBarView.placeholder = "Search" searchBarView.placeholder = "Search"
searchBarView.tintColor = MaterialColor.white searchBarView.tintColor = MaterialColor.white
searchBarView.textColor = MaterialColor.white searchBarView.textColor = MaterialColor.white
searchBarView.placeholderTextColor = MaterialColor.white searchBarView.placeholderTextColor = MaterialColor.white
searchBarView.textField.font = RobotoFont.regularWithSize(22) searchBarView.textField.font = RobotoFont.regularWithSize(22)
searchBarView.clearButton = clearButton
searchBarView.leftControls = [menuButton] searchBarView.leftControls = [menuButton]
// searchBarView.rightControls = [searchButton] searchBarView.rightControls = [searchButton]
view.addSubview(searchBarView) view.addSubview(searchBarView)
searchBarView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.height(view, child: searchBarView, height: 70)
MaterialLayout.alignFromTop(view, child: searchBarView)
MaterialLayout.alignToParentHorizontally(view, child: searchBarView)
} }
} }
...@@ -142,6 +142,7 @@ public class NavigationBarView : MaterialView { ...@@ -142,6 +142,7 @@ public class NavigationBarView : MaterialView {
v.grid.rows = 2 v.grid.rows = 2
} }
// Column adjustment.
width = UIScreen.mainScreen().bounds.width width = UIScreen.mainScreen().bounds.width
grid.axis.columns = Int(width / 48) grid.axis.columns = Int(width / 48)
reloadView() reloadView()
......
...@@ -42,29 +42,6 @@ public class SearchBarView : MaterialView { ...@@ -42,29 +42,6 @@ public class SearchBarView : MaterialView {
} }
/** /**
:name: contentInsets
*/
public var contentInsetPreset: MaterialEdgeInset = .None {
didSet {
contentInset = MaterialEdgeInsetToValue(contentInsetPreset)
}
}
/// Wrapper around grid.contentInset.
public var contentInset: UIEdgeInsets = UIEdgeInsetsZero {
didSet {
grid.contentInset = contentInset
}
}
/// Wrapper around grid.spacing.
public var spacing: CGFloat = 0 {
didSet {
grid.spacing = spacing
}
}
/**
:name: leftControls :name: leftControls
*/ */
public var leftControls: Array<UIControl>? { public var leftControls: Array<UIControl>? {
...@@ -127,36 +104,56 @@ public class SearchBarView : MaterialView { ...@@ -127,36 +104,56 @@ public class SearchBarView : 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 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?(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) { public convenience init?(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(leftControls, rightControls: rightControls) prepareProperties(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
height = 44
default:
grid.contentInset.top = 20
grid.contentInset.bottom = 8
height = 64
}
// Column adjustment.
width = UIScreen.mainScreen().bounds.width
grid.axis.columns = Int(width / 48)
reloadView() reloadView()
} }
...@@ -165,9 +162,7 @@ public class SearchBarView : MaterialView { ...@@ -165,9 +162,7 @@ public class SearchBarView : MaterialView {
reloadView() reloadView()
} }
/** /// Reloads the view.
:name: reloadView
*/
public func reloadView() { public func reloadView() {
layoutIfNeeded() layoutIfNeeded()
...@@ -230,17 +225,20 @@ public class SearchBarView : MaterialView { ...@@ -230,17 +225,20 @@ public class SearchBarView : 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
prepareTextField() prepareTextField()
} }
...@@ -250,14 +248,6 @@ public class SearchBarView : MaterialView { ...@@ -250,14 +248,6 @@ public class SearchBarView : MaterialView {
textField.text = "" textField.text = ""
} }
/**
:name: prepareProperties
*/
private func prepareProperties(leftControls: Array<UIControl>?, rightControls: Array<UIControl>?) {
self.leftControls = leftControls
self.rightControls = rightControls
}
/// Prepares the textField. /// Prepares the textField.
private func prepareTextField() { private func prepareTextField() {
textField.placeholder = "Search" textField.placeholder = "Search"
...@@ -266,4 +256,16 @@ public class SearchBarView : MaterialView { ...@@ -266,4 +256,16 @@ public class SearchBarView : MaterialView {
textField.rightViewMode = .WhileEditing textField.rightViewMode = .WhileEditing
addSubview(textField) addSubview(textField)
} }
/**
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.
*/
private func prepareProperties(leftControls: Array<UIControl>?, rightControls: Array<UIControl>?) {
self.leftControls = leftControls
self.rightControls = rightControls
}
} }
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