Commit 588b6f70 by Daniel Dahan

updated example projects that use SearchBar and the SearchBar defaults

parent b54e9c05
...@@ -74,20 +74,12 @@ class AppSearchBarController: SearchBarController { ...@@ -74,20 +74,12 @@ class AppSearchBarController: SearchBarController {
/// Prepares the searchBar. /// Prepares the searchBar.
private func prepareSearchBar() { private func prepareSearchBar() {
var image: UIImage? = MaterialIcon.cm.close var image: UIImage? = MaterialIcon.cm.arrowBack
let clearButton: FlatButton = FlatButton()
clearButton.pulseScale = false
clearButton.pulseColor = MaterialColor.grey.darken4
clearButton.tintColor = MaterialColor.grey.darken4
clearButton.setImage(image, forState: .Normal)
clearButton.setImage(image, forState: .Highlighted)
// Back button. // Back button.
image = MaterialIcon.cm.arrowBack
let backButton: FlatButton = FlatButton() let backButton: FlatButton = FlatButton()
backButton.pulseScale = false backButton.pulseScale = false
backButton.pulseColor = MaterialColor.grey.darken4 backButton.pulseColor = MaterialColor.grey.base
backButton.tintColor = MaterialColor.grey.darken4 backButton.tintColor = MaterialColor.grey.darken4
backButton.setImage(image, forState: .Normal) backButton.setImage(image, forState: .Normal)
backButton.setImage(image, forState: .Highlighted) backButton.setImage(image, forState: .Highlighted)
...@@ -97,19 +89,12 @@ class AppSearchBarController: SearchBarController { ...@@ -97,19 +89,12 @@ class AppSearchBarController: SearchBarController {
image = MaterialIcon.cm.moreHorizontal image = MaterialIcon.cm.moreHorizontal
let moreButton: FlatButton = FlatButton() let moreButton: FlatButton = FlatButton()
moreButton.pulseScale = false moreButton.pulseScale = false
moreButton.pulseColor = MaterialColor.grey.darken4 moreButton.pulseColor = MaterialColor.grey.base
moreButton.tintColor = MaterialColor.grey.darken4 moreButton.tintColor = MaterialColor.grey.darken4
moreButton.setImage(image, forState: .Normal) moreButton.setImage(image, forState: .Normal)
moreButton.setImage(image, forState: .Highlighted) moreButton.setImage(image, forState: .Highlighted)
searchBar.placeholder = "Search"
searchBar.tintColor = MaterialColor.grey.darken4
searchBar.textColor = MaterialColor.grey.darken4
searchBar.placeholderTextColor = MaterialColor.grey.darken4
searchBar.textField.font = RobotoFont.regular
searchBar.textField.delegate = self searchBar.textField.delegate = self
searchBar.clearButton = clearButton
searchBar.leftControls = [backButton] searchBar.leftControls = [backButton]
searchBar.rightControls = [moreButton] searchBar.rightControls = [moreButton]
} }
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
96BCB86A1CB4B3D700C806FE /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96BCB8691CB4B3D700C806FE /* Material.framework */; };
96BCB86B1CB4B3D700C806FE /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96BCB8691CB4B3D700C806FE /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96F2F1E51C97A5C800A5FE27 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1DF1C97A5C800A5FE27 /* AppDelegate.swift */; }; 96F2F1E51C97A5C800A5FE27 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F2F1DF1C97A5C800A5FE27 /* AppDelegate.swift */; };
96F2F1E61C97A5C800A5FE27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1E01C97A5C800A5FE27 /* Assets.xcassets */; }; 96F2F1E61C97A5C800A5FE27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1E01C97A5C800A5FE27 /* Assets.xcassets */; };
96F2F1E71C97A5C800A5FE27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1E11C97A5C800A5FE27 /* LaunchScreen.storyboard */; }; 96F2F1E71C97A5C800A5FE27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1E11C97A5C800A5FE27 /* LaunchScreen.storyboard */; };
...@@ -20,6 +22,7 @@ ...@@ -20,6 +22,7 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
96BCB86B1CB4B3D700C806FE /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -28,6 +31,7 @@ ...@@ -28,6 +31,7 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
96A71F041C718F8800C0C4AE /* SearchBar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SearchBar.app; sourceTree = BUILT_PRODUCTS_DIR; }; 96A71F041C718F8800C0C4AE /* SearchBar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SearchBar.app; sourceTree = BUILT_PRODUCTS_DIR; };
96BCB8691CB4B3D700C806FE /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-bshwisidfobstlbomegqyybbrygh/Build/Products/Debug-iphonesimulator/Material.framework"; sourceTree = "<absolute>"; };
96F2F1DF1C97A5C800A5FE27 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 96F2F1DF1C97A5C800A5FE27 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
96F2F1E01C97A5C800A5FE27 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 96F2F1E01C97A5C800A5FE27 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
96F2F1E21C97A5C800A5FE27 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 96F2F1E21C97A5C800A5FE27 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
...@@ -40,6 +44,7 @@ ...@@ -40,6 +44,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
96BCB86A1CB4B3D700C806FE /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -49,6 +54,7 @@ ...@@ -49,6 +54,7 @@
96A71EFB1C718F8800C0C4AE = { 96A71EFB1C718F8800C0C4AE = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96BCB8691CB4B3D700C806FE /* Material.framework */,
96F2F1DE1C97A5C800A5FE27 /* SearchBar */, 96F2F1DE1C97A5C800A5FE27 /* SearchBar */,
96A71F051C718F8800C0C4AE /* Products */, 96A71F051C718F8800C0C4AE /* Products */,
); );
......
...@@ -36,7 +36,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -36,7 +36,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow? var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds) window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = ViewController() window!.rootViewController = ViewController()
window!.makeKeyAndVisible() window!.makeKeyAndVisible()
return true return true
......
...@@ -54,21 +54,13 @@ class ViewController: UIViewController { ...@@ -54,21 +54,13 @@ class ViewController: UIViewController {
/// Prepare toolbar. /// Prepare toolbar.
private func prepareSearchBar() { private func prepareSearchBar() {
var image: UIImage? = MaterialIcon.cm.close var image: UIImage? = MaterialIcon.cm.arrowBack
let clearButton: FlatButton = FlatButton()
clearButton.pulseScale = false
clearButton.pulseColor = MaterialColor.blueGrey.darken4
clearButton.tintColor = MaterialColor.blueGrey.darken4
clearButton.setImage(image, forState: .Normal)
clearButton.setImage(image, forState: .Highlighted)
// Back button. // Back button.
image = MaterialIcon.cm.arrowBack
let backButton: FlatButton = FlatButton() let backButton: FlatButton = FlatButton()
backButton.pulseScale = false backButton.pulseScale = false
backButton.pulseColor = MaterialColor.blueGrey.darken4 backButton.pulseColor = MaterialColor.grey.base
backButton.tintColor = MaterialColor.blueGrey.darken4 backButton.tintColor = MaterialColor.grey.darken4
backButton.setImage(image, forState: .Normal) backButton.setImage(image, forState: .Normal)
backButton.setImage(image, forState: .Highlighted) backButton.setImage(image, forState: .Highlighted)
...@@ -79,8 +71,8 @@ class ViewController: UIViewController { ...@@ -79,8 +71,8 @@ class ViewController: UIViewController {
image = MaterialIcon.cm.moreHorizontal image = MaterialIcon.cm.moreHorizontal
let moreButton: FlatButton = FlatButton() let moreButton: FlatButton = FlatButton()
moreButton.pulseScale = false moreButton.pulseScale = false
moreButton.pulseColor = MaterialColor.blueGrey.darken4 moreButton.pulseColor = MaterialColor.grey.base
moreButton.tintColor = MaterialColor.blueGrey.darken4 moreButton.tintColor = MaterialColor.grey.darken4
moreButton.setImage(image, forState: .Normal) moreButton.setImage(image, forState: .Normal)
moreButton.setImage(image, forState: .Highlighted) moreButton.setImage(image, forState: .Highlighted)
...@@ -90,14 +82,6 @@ class ViewController: UIViewController { ...@@ -90,14 +82,6 @@ class ViewController: UIViewController {
to your info.plist file and set the following property. to your info.plist file and set the following property.
*/ */
searchBar.statusBarStyle = .Default searchBar.statusBarStyle = .Default
searchBar.placeholder = "Search"
searchBar.tintColor = MaterialColor.blueGrey.darken4
searchBar.textColor = MaterialColor.blueGrey.darken4
searchBar.placeholderTextColor = MaterialColor.blueGrey.darken4
searchBar.textField.font = RobotoFont.regular
searchBar.clearButton = clearButton
searchBar.leftControls = [backButton] searchBar.leftControls = [backButton]
searchBar.rightControls = [switchControl, moreButton] searchBar.rightControls = [switchControl, moreButton]
......
...@@ -76,18 +76,9 @@ class AppSearchBarController: SearchBarController { ...@@ -76,18 +76,9 @@ class AppSearchBarController: SearchBarController {
/// Prepares the searchBar. /// Prepares the searchBar.
private func prepareSearchBar() { private func prepareSearchBar() {
var image: UIImage? = MaterialIcon.cm.close var image: UIImage? = MaterialIcon.cm.arrowBack
let clearButton: FlatButton = FlatButton()
clearButton.pulseColor = nil
clearButton.pulseScale = false
clearButton.tintColor = MaterialColor.blueGrey.darken4
clearButton.setImage(image, forState: .Normal)
clearButton.setImage(image, forState: .Highlighted)
clearButton.addTarget(self, action: #selector(handleYellowButton), forControlEvents: .TouchUpInside)
// Back button. // Back button.
image = MaterialIcon.cm.arrowBack
let backButton: FlatButton = FlatButton() let backButton: FlatButton = FlatButton()
backButton.pulseColor = nil backButton.pulseColor = nil
backButton.pulseScale = false backButton.pulseScale = false
...@@ -112,15 +103,7 @@ class AppSearchBarController: SearchBarController { ...@@ -112,15 +103,7 @@ class AppSearchBarController: SearchBarController {
to your info.plist file and set the following property. to your info.plist file and set the following property.
*/ */
searchBar.statusBarStyle = .Default searchBar.statusBarStyle = .Default
searchBar.placeholder = "Search"
searchBar.tintColor = MaterialColor.blueGrey.darken4
searchBar.textColor = MaterialColor.blueGrey.darken4
searchBar.placeholderTextColor = MaterialColor.blueGrey.darken4
searchBar.textField.font = RobotoFont.regular
searchBar.textField.delegate = self searchBar.textField.delegate = self
searchBar.clearButton = clearButton
searchBar.leftControls = [backButton] searchBar.leftControls = [backButton]
searchBar.rightControls = [moreButton] searchBar.rightControls = [moreButton]
} }
......
...@@ -32,36 +32,57 @@ import UIKit ...@@ -32,36 +32,57 @@ import UIKit
public class SearchBar : StatusBarView { public class SearchBar : StatusBarView {
/// The UITextField for the searchBar. /// The UITextField for the searchBar.
public private(set) lazy var textField: TextField = TextField() public private(set) var textField: UITextField!
/// Reference to the clearButton.
public private(set) var clearButton: FlatButton!
/// Handle the clearButton manually.
@IBInspectable public var clearButtonAutoHandleEnabled: Bool = true {
didSet {
clearButton.removeTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
if clearButtonAutoHandleEnabled {
clearButton.addTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
}
}
}
/// TintColor for searchBar. /// TintColor for searchBar.
@IBInspectable public override var tintColor: UIColor? { @IBInspectable public override var tintColor: UIColor? {
didSet { get {
textField.tintColor = tintColor return textField.tintColor
}
set(value) {
textField.tintColor = value
} }
} }
/// TextColor for searchBar. /// TextColor for searchBar.
@IBInspectable public var textColor: UIColor? { @IBInspectable public var textColor: UIColor? {
didSet { get {
textField.textColor = textColor return textField.textColor
}
set(value) {
textField.textColor = value
} }
} }
/// A wrapper for searchBar.placeholder. /// A wrapper for searchBar.placeholder.
@IBInspectable public var placeholder: String? { @IBInspectable public var placeholder: String? {
didSet { get {
textField.placeholder = placeholder return textField.placeholder
}
set(value) {
textField.placeholder = value
} }
} }
/// Placeholder textColor. /// Placeholder textColor.
@IBInspectable public var placeholderTextColor: UIColor { @IBInspectable public var placeholderTextColor: UIColor = MaterialColor.grey.base {
get { didSet {
return textField.placeholderTextColor if let v: String = textField.placeholder {
} textField.attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor])
set(value) { }
textField.placeholderTextColor = value
} }
} }
...@@ -75,23 +96,55 @@ public class SearchBar : StatusBarView { ...@@ -75,23 +96,55 @@ public class SearchBar : StatusBarView {
if willRenderView { if willRenderView {
contentView.grid.views?.append(textField) contentView.grid.views?.append(textField)
contentView.grid.reloadLayout() contentView.grid.reloadLayout()
textField.font = textField.font?.fontWithSize(20) reloadView()
textField.reloadView()
} }
} }
/// Reloads the view.
public func reloadView() {
/// Align the clearButton.
let h: CGFloat = textField.frame.height
clearButton.frame = CGRectMake(textField.frame.width - h, 0, h, h)
}
/// Prepares the contentView. /// Prepares the contentView.
public override func prepareContentView() { public override func prepareContentView() {
super.prepareContentView() super.prepareContentView()
prepareTextField() prepareTextField()
prepareClearButton()
} }
/// Clears the textField text.
internal func handleClearButton() {
textField.text = ""
}
/// Prepares the textField. /// Prepares the textField.
private func prepareTextField() { private func prepareTextField() {
textField.placeholder = "Search" textField = UITextField()
textField.font = RobotoFont.regularWithSize(20)
textField.backgroundColor = MaterialColor.clear textField.backgroundColor = MaterialColor.clear
textField.clearButtonMode = .WhileEditing textField.clearButtonMode = .WhileEditing
tintColor = MaterialColor.grey.darken4
textColor = MaterialColor.grey.darken4
placeholder = "Search"
placeholderTextColor = MaterialColor.grey.base
contentView.addSubview(textField) contentView.addSubview(textField)
} }
/// Prepares the clearButton.
private func prepareClearButton() {
let image: UIImage? = MaterialIcon.cm.close
clearButton = FlatButton()
clearButton.contentEdgeInsets = UIEdgeInsetsZero
clearButton.pulseColor = MaterialColor.grey.base
clearButton.pulseScale = false
clearButton.tintColor = MaterialColor.grey.darken4
clearButton.setImage(image, forState: .Normal)
clearButton.setImage(image, forState: .Highlighted)
clearButtonAutoHandleEnabled = true
textField.clearButtonMode = .Never
textField.rightViewMode = .WhileEditing
textField.rightView = clearButton
}
} }
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