Commit c05511dc by Daniel Dahan

added lineLayer colors

parent 588b6f70
......@@ -7,8 +7,6 @@
objects = {
/* 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 */; };
96F2F1E61C97A5C800A5FE27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1E01C97A5C800A5FE27 /* Assets.xcassets */; };
96F2F1E71C97A5C800A5FE27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96F2F1E11C97A5C800A5FE27 /* LaunchScreen.storyboard */; };
......@@ -22,7 +20,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
96BCB86B1CB4B3D700C806FE /* Material.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -31,7 +28,6 @@
/* Begin PBXFileReference section */
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>"; };
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>"; };
......@@ -44,7 +40,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
96BCB86A1CB4B3D700C806FE /* Material.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -54,7 +49,6 @@
96A71EFB1C718F8800C0C4AE = {
isa = PBXGroup;
children = (
96BCB8691CB4B3D700C806FE /* Material.framework */,
96F2F1DE1C97A5C800A5FE27 /* SearchBar */,
96A71F051C718F8800C0C4AE /* Products */,
);
......
......@@ -37,7 +37,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = AppSearchBarController(rootViewController: YellowViewController())
window!.makeKeyAndVisible()
return true
......
......@@ -53,23 +53,16 @@ class ViewController: UIViewController, TextFieldDelegate {
/// Prepares the name TextField.
private func prepareNameField() {
let textField: TextField = TextField(frame: CGRectMake(57, 100, 300, 24))
let textField: TextField = TextField(frame: CGRectMake(57, 100, 300, 32))
textField.placeholder = "First Name"
textField.placeholderTextColor = MaterialColor.grey.base
textField.font = RobotoFont.regularWithSize(20)
textField.textColor = MaterialColor.black
view.addSubview(textField)
}
/// Prepares the email TextField.
private func prepareEmailField() {
let textField: TextField = TextField(frame: CGRectMake(57, 200, 300, 24))
let textField: TextField = TextField(frame: CGRectMake(57, 200, 300, 32))
textField.delegate = self
textField.placeholder = "Email"
textField.placeholderTextColor = MaterialColor.grey.base
textField.font = RobotoFont.regularWithSize(20)
textField.textColor = MaterialColor.black
/*
Used to display the error message, which is displayed when
......@@ -79,7 +72,7 @@ class ViewController: UIViewController, TextFieldDelegate {
textField.detailLabel!.text = "Email is incorrect."
textField.detailLabel!.font = RobotoFont.mediumWithSize(12)
textField.detailLabelActiveColor = MaterialColor.red.accent3
// textField.detailLabelAutoHideEnabled = false // Uncomment this line to have manual hiding.
textField.detailLabelAutoHideEnabled = false // Uncomment this line to have manual hiding.
view.addSubview(textField)
}
......
......@@ -57,20 +57,12 @@ class ViewController: UIViewController, TextFieldDelegate {
/// Prepares the name TextField.
private func prepareNameField() {
nameField.placeholder = "First Name"
nameField.placeholderTextColor = MaterialColor.grey.base
nameField.font = RobotoFont.regularWithSize(20)
nameField.textColor = MaterialColor.black
nameField.borderStyle = .None
}
/// Prepares the email TextField.
private func prepareEmailField() {
emailField.delegate = self
emailField.placeholder = "Email"
emailField.placeholderTextColor = MaterialColor.grey.base
emailField.font = RobotoFont.regularWithSize(20)
emailField.textColor = MaterialColor.black
emailField.borderStyle = .None
/*
Used to display the error message, which is displayed when
......
......@@ -365,9 +365,11 @@ Add a new dimension of interactivity with CaptureView. CaptureView is a fully fu
* TabBarController
* Scrolling Techniques
* Snackbar
* BottomNavigationController with Snackbar.
* Bottom Sheets
* Dialogs
* Collapsing Toolbar
* RTL Support
* Advanced Camera / Audio Toolset & Views
* More Examples
......
......@@ -125,7 +125,7 @@ public class SearchBar : StatusBarView {
textField.font = RobotoFont.regularWithSize(20)
textField.backgroundColor = MaterialColor.clear
textField.clearButtonMode = .WhileEditing
tintColor = MaterialColor.grey.darken4
tintColor = MaterialColor.grey.base
textColor = MaterialColor.grey.darken4
placeholder = "Search"
placeholderTextColor = MaterialColor.grey.base
......@@ -139,7 +139,7 @@ public class SearchBar : StatusBarView {
clearButton.contentEdgeInsets = UIEdgeInsetsZero
clearButton.pulseColor = MaterialColor.grey.base
clearButton.pulseScale = false
clearButton.tintColor = MaterialColor.grey.darken4
clearButton.tintColor = MaterialColor.grey.base
clearButton.setImage(image, forState: .Normal)
clearButton.setImage(image, forState: .Highlighted)
clearButtonAutoHandleEnabled = true
......
......@@ -34,6 +34,9 @@ public protocol TextFieldDelegate : UITextFieldDelegate {}
@IBDesignable
public class TextField : UITextField {
/// A reference to the placeholder value.
private var placeholderText: String?
/**
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame.
......@@ -248,13 +251,29 @@ public class TextField : UITextField {
public private(set) var clearButton: FlatButton!
/// The bottom border layer.
public private(set) lazy var bottomBorderLayer: CAShapeLayer = CAShapeLayer()
public private(set) lazy var lineLayer: CAShapeLayer = CAShapeLayer()
/**
A property that sets the distance between the textField and
bottomBorderLayer.
lineLayer.
*/
@IBInspectable public var bottomBorderLayerDistance: CGFloat = 4
@IBInspectable public var lineLayerDistance: CGFloat = 4
/// The lineLayer color when inactive.
@IBInspectable public var lineLayerColor: UIColor? {
didSet {
lineLayer.backgroundColor = lineLayerColor?.CGColor
}
}
/// The lineLayer active color.
@IBInspectable public var lineLayerActiveColor: UIColor?
/// The lineLayer detail color when inactive.
@IBInspectable public var lineLayerDetailColor: UIColor?
/// The lineLayer detail active color.
@IBInspectable public var lineLayerDetailActiveColor: UIColor?
/**
The title UILabel that is displayed when there is text. The
......@@ -267,20 +286,26 @@ public class TextField : UITextField {
@IBInspectable public var titleLabelColor: UIColor? {
didSet {
titleLabel.textColor = titleLabelColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.titleLabelColor?.CGColor
if nil == lineLayerColor {
lineLayerColor = titleLabelColor
}
}
}
/// The color of the titleLabel text when the textField is active.
@IBInspectable public var titleLabelActiveColor: UIColor?
@IBInspectable public var titleLabelActiveColor: UIColor? {
didSet {
if nil == lineLayerActiveColor {
lineLayerActiveColor = titleLabelActiveColor
}
}
}
/**
A property that sets the distance between the textField and
titleLabel.
*/
@IBInspectable public var titleLabelAnimationDistance: CGFloat = 8
@IBInspectable public var titleLabelAnimationDistance: CGFloat = 4
/// An override to the text property.
@IBInspectable public override var text: String? {
......@@ -307,8 +332,8 @@ public class TextField : UITextField {
didSet {
if !detailLabelHidden {
detailLabel?.textColor = detailLabelActiveColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.detailLabelActiveColor?.CGColor
if nil == lineLayerDetailActiveColor {
lineLayerDetailActiveColor = detailLabelActiveColor
}
}
}
......@@ -333,15 +358,11 @@ public class TextField : UITextField {
didSet {
if detailLabelHidden {
detailLabel?.textColor = titleLabelColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.editing ? self.titleLabelActiveColor?.CGColor : self.titleLabelColor?.CGColor
}
lineLayer.backgroundColor = (editing ? lineLayerActiveColor : lineLayerColor)?.CGColor
hideDetailLabel()
} else {
detailLabel?.textColor = detailLabelActiveColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.detailLabelActiveColor?.CGColor
}
lineLayer.backgroundColor = (nil == lineLayerDetailActiveColor ? detailLabelActiveColor : lineLayerDetailActiveColor)?.CGColor
showDetailLabel()
}
}
......@@ -394,7 +415,7 @@ public class TextField : UITextField {
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
bottomBorderLayer.frame = CGRectMake(0, bounds.height + bottomBorderLayerDistance, bounds.width, 1)
layoutLineLayer()
layoutShadowPath()
}
}
......@@ -463,9 +484,13 @@ public class TextField : UITextField {
public func prepareView() {
backgroundColor = MaterialColor.white
masksToBounds = false
prepareBottomBorderLayer()
placeholderTextColor = MaterialColor.grey.base
font = RobotoFont.regularWithSize(20)
textColor = MaterialColor.grey.darken4
borderStyle = .None
prepareClearButton()
prepareTitleLabel()
prepareLineLayer()
reloadView()
}
......@@ -485,27 +510,20 @@ public class TextField : UITextField {
internal func textFieldValueChanged() {
if detailLabelAutoHideEnabled && !detailLabelHidden {
detailLabelHidden = true
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.titleLabelActiveColor?.CGColor
}
lineLayer.backgroundColor = (nil == lineLayerActiveColor ? titleLabelActiveColor : lineLayerActiveColor)?.CGColor
}
}
/// Handler for text editing began.
internal func textFieldDidBegin() {
showTitleLabel()
titleLabel.textColor = titleLabelActiveColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.detailLabelHidden ? self.titleLabelActiveColor?.CGColor : self.detailLabelActiveColor?.CGColor
}
lineLayer.frame = CGRectMake(0, bounds.height + lineLayerDistance, bounds.width, 2)
lineLayer.backgroundColor = (detailLabelHidden ? nil == lineLayerActiveColor ? titleLabelActiveColor : lineLayerActiveColor : nil == lineLayerDetailActiveColor ? detailLabelActiveColor : lineLayerDetailActiveColor)?.CGColor
}
/// Handler for text changed.
internal func textFieldDidChange() {
if 0 < text?.utf16.count {
showTitleLabel()
} else if 0 == text?.utf16.count {
hideTitleLabel()
}
sendActionsForControlEvents(.ValueChanged)
}
......@@ -517,9 +535,8 @@ public class TextField : UITextField {
hideTitleLabel()
}
titleLabel.textColor = titleLabelColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.detailLabelHidden ? self.titleLabelColor?.CGColor : self.detailLabelActiveColor?.CGColor
}
lineLayer.frame = CGRectMake(0, bounds.height + lineLayerDistance, bounds.width, 1)
lineLayer.backgroundColor = (detailLabelHidden ? nil == lineLayerColor ? titleLabelColor : lineLayerColor : nil == lineLayerDetailColor ? detailLabelActiveColor : lineLayerDetailColor)?.CGColor
}
/// Sets the shadow path.
......@@ -535,7 +552,7 @@ public class TextField : UITextField {
}
}
/// Prepares the titleLabel property.
/// Prepares the titleLabel.
private func prepareTitleLabel() {
titleLabel = UILabel()
titleLabel.hidden = true
......@@ -554,7 +571,7 @@ public class TextField : UITextField {
addTarget(self, action: #selector(textFieldDidEnd), forControlEvents: .EditingDidEnd)
}
/// Prepares the detailLabel property.
/// Prepares the detailLabel.
private func prepareDetailLabel() {
if let v: UILabel = detailLabel {
v.hidden = true
......@@ -573,9 +590,16 @@ public class TextField : UITextField {
}
}
/// Prepares the bottomBorderLayer property.
private func prepareBottomBorderLayer() {
layer.addSublayer(bottomBorderLayer)
/// Prepares the lineLayer.
private func prepareLineLayer() {
layoutLineLayer()
layer.addSublayer(lineLayer)
}
/// Layout the lineLayer.
private func layoutLineLayer() {
let h: CGFloat = 1 < lineLayer.frame.height ? lineLayer.frame.height : 1
lineLayer.frame = CGRectMake(0, bounds.height + lineLayerDistance, bounds.width, h)
}
/// Prepares the clearButton.
......@@ -598,26 +622,29 @@ public class TextField : UITextField {
private func showTitleLabel() {
if titleLabel.hidden {
if let s: String = placeholder {
if 0 == titleLabel.text?.utf16.count || nil == titleLabel.text {
titleLabel.text = s
}
titleLabel.text = s
placeholderText = s
placeholder = nil
}
let h: CGFloat = ceil(titleLabel.font.lineHeight)
titleLabel.frame = CGRectMake(0, -h, bounds.width, h)
titleLabel.frame = bounds
titleLabel.font = font
titleLabel.hidden = false
UIView.animateWithDuration(0.25, animations: { [unowned self] in
UIView.animateWithDuration(0.15, animations: { [unowned self] in
self.titleLabel.alpha = 1
self.titleLabel.frame.origin.y -= self.titleLabelAnimationDistance
self.titleLabel.font = self.font?.fontWithSize(12)
self.titleLabel.frame = CGRectMake(0, -(self.titleLabelAnimationDistance + h), self.bounds.width, h)
})
}
}
/// Hides and animates the titleLabel property.
private func hideTitleLabel() {
UIView.animateWithDuration(0.25, animations: { [unowned self] in
self.titleLabel.alpha = 0
self.titleLabel.frame.origin.y += self.titleLabelAnimationDistance
}) { _ in
UIView.animateWithDuration(0.15, animations: { [unowned self] in
self.titleLabel.font = self.font
self.titleLabel.frame = self.bounds
}) { [unowned self] _ in
self.placeholder = self.placeholderText
self.titleLabel.hidden = true
}
}
......@@ -627,10 +654,10 @@ public class TextField : UITextField {
if let v: UILabel = detailLabel {
if v.hidden {
let h: CGFloat = ceil(v.font.lineHeight)
v.frame = CGRectMake(0, bounds.height + bottomBorderLayerDistance, bounds.width, h)
v.frame = CGRectMake(0, bounds.height + lineLayerDistance, bounds.width, h)
v.hidden = false
UIView.animateWithDuration(0.25, animations: { [unowned self] in
v.frame.origin.y = self.frame.height + self.bottomBorderLayerDistance + self.detailLabelAnimationDistance
UIView.animateWithDuration(0.15, animations: { [unowned self] in
v.frame.origin.y = self.frame.height + self.lineLayerDistance + self.detailLabelAnimationDistance
v.alpha = 1
})
}
......@@ -640,7 +667,7 @@ public class TextField : UITextField {
/// Hides and animates the detailLabel property.
private func hideDetailLabel() {
if let v: UILabel = detailLabel {
UIView.animateWithDuration(0.25, animations: { [unowned self] in
UIView.animateWithDuration(0.15, animations: { [unowned self] in
v.alpha = 0
v.frame.origin.y -= self.detailLabelAnimationDistance
}) { _ in
......
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