Commit ba7f21c2 by Daniel Dahan

updated SearchBarView

parent 3744a4a9
......@@ -38,10 +38,13 @@ import UIKit
import Material
class ViewController: UIViewController {
/// Reference for NavigationBarView.
private var navigationBarView: NavigationBarView = NavigationBarView()
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareAlignTitleAndDetailLabelToLeftExample()
prepareNavigationBarView()
}
/// General preparation statements.
......@@ -49,25 +52,14 @@ class ViewController: UIViewController {
view.backgroundColor = MaterialColor.white
}
/// Prepares a text alignment example.
private func prepareAlignTitleAndDetailLabelToLeftExample() {
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
/// Prepares the navigationBarView
private func prepareNavigationBarView() {
// Title label.
let titleLabel: UILabel = UILabel()
titleLabel.text = "Material"
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(17)
navigationBarView.titleLabel = titleLabel
// Detail label.
let detailLabel: UILabel = UILabel()
......@@ -75,31 +67,38 @@ class ViewController: UIViewController {
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regularWithSize(12)
navigationBarView.detailLabel = detailLabel
var image = UIImage(named: "ic_menu_white")
// Menu button.
let img1: UIImage? = UIImage(named: "ic_menu_white")
let menuButton: FlatButton = FlatButton()
menuButton.pulseColor = nil
menuButton.pulseScale = false
menuButton.setImage(img1, forState: .Normal)
menuButton.setImage(img1, forState: .Highlighted)
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
// Star button.
let switchControl: MaterialSwitch = MaterialSwitch(state: .On, style: .Light)
// Search button.
let img3: UIImage? = UIImage(named: "ic_search_white")
image = UIImage(named: "ic_search_white")
let searchButton: FlatButton = FlatButton()
searchButton.pulseColor = nil
searchButton.pulseScale = false
searchButton.setImage(img3, forState: .Normal)
searchButton.setImage(img3, forState: .Highlighted)
searchButton.setImage(image, forState: .Normal)
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]
view.addSubview(navigationBarView)
......
......@@ -36,8 +36,8 @@ import UIKit
import Material
class ViewController: UIViewController {
/// Reference for NavigationBarView.
private var searchBarView: SearchBarView = SearchBarView(frame: CGRectNull)
/// Reference for SearchBarView.
private var searchBarView: SearchBarView = SearchBarView()
override func viewDidLoad() {
super.viewDidLoad()
......@@ -52,41 +52,46 @@ class ViewController: UIViewController {
/// Prepare navigationBarView.
private func prepareSearchBarView() {
searchBarView.statusBarStyle = .LightContent
searchBarView.backgroundColor = MaterialColor.blue.base
var image = UIImage(named: "ic_close_white")
let clearButton: FlatButton = FlatButton()
clearButton.pulseColor = MaterialColor.white
clearButton.pulseColor = nil
clearButton.pulseScale = false
clearButton.setImage(image, forState: .Normal)
clearButton.setImage(image, forState: .Highlighted)
searchBarView.clearButton = clearButton
image = UIImage(named: "ic_menu_white")
let menuButton: FlatButton = FlatButton()
menuButton.pulseColor = MaterialColor.white
menuButton.pulseColor = nil
menuButton.pulseScale = false
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
image = UIImage(named: "ic_search_white")
let searchButton: FlatButton = FlatButton()
searchButton.pulseColor = MaterialColor.white
searchButton.pulseColor = nil
searchButton.pulseScale = false
searchButton.setImage(image, forState: .Normal)
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.tintColor = MaterialColor.white
searchBarView.textColor = MaterialColor.white
searchBarView.placeholderTextColor = MaterialColor.white
searchBarView.textField.font = RobotoFont.regularWithSize(22)
searchBarView.clearButton = clearButton
searchBarView.leftControls = [menuButton]
// searchBarView.rightControls = [searchButton]
searchBarView.rightControls = [searchButton]
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 {
v.grid.rows = 2
}
// Column adjustment.
width = UIScreen.mainScreen().bounds.width
grid.axis.columns = Int(width / 48)
reloadView()
......
......@@ -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
*/
public var leftControls: Array<UIControl>? {
......@@ -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) {
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) {
super.init(frame: frame)
}
/**
:name: init
*/
/// A convenience initializer.
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) {
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)
}
public override func 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()
}
......@@ -165,9 +162,7 @@ public class SearchBarView : MaterialView {
reloadView()
}
/**
:name: reloadView
*/
/// Reloads the view.
public func reloadView() {
layoutIfNeeded()
......@@ -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() {
super.prepareView()
grid.spacing = 10
grid.axis.columns = 8
grid.spacing = 8
grid.axis.inherited = false
grid.contentInset.top = 25
grid.contentInset.left = 10
grid.contentInset.bottom = 10
grid.contentInset.right = 10
grid.contentInset.top = 20
grid.contentInset.left = 8
grid.contentInset.bottom = 8
grid.contentInset.right = 8
depth = .Depth1
prepareTextField()
}
......@@ -250,14 +248,6 @@ public class SearchBarView : MaterialView {
textField.text = ""
}
/**
:name: prepareProperties
*/
private func prepareProperties(leftControls: Array<UIControl>?, rightControls: Array<UIControl>?) {
self.leftControls = leftControls
self.rightControls = rightControls
}
/// Prepares the textField.
private func prepareTextField() {
textField.placeholder = "Search"
......@@ -266,4 +256,16 @@ public class SearchBarView : MaterialView {
textField.rightViewMode = .WhileEditing
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