Commit 541aaec7 by Daniel Dahan

added MTextField for testing

parent 2f724180
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
961776711CCE75EB0091B4F3 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 961776701CCE75EB0091B4F3 /* Material.framework */; };
961776721CCE75EB0091B4F3 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 961776701CCE75EB0091B4F3 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
966F57A11C226BAA009185B7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57A01C226BAA009185B7 /* AppDelegate.swift */; }; 966F57A11C226BAA009185B7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57A01C226BAA009185B7 /* AppDelegate.swift */; };
966F57A31C226BAA009185B7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57A21C226BAA009185B7 /* ViewController.swift */; }; 966F57A31C226BAA009185B7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57A21C226BAA009185B7 /* ViewController.swift */; };
966F57A81C226BAA009185B7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 966F57A71C226BAA009185B7 /* Assets.xcassets */; }; 966F57A81C226BAA009185B7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 966F57A71C226BAA009185B7 /* Assets.xcassets */; };
...@@ -22,7 +20,6 @@ ...@@ -22,7 +20,6 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
961776721CCE75EB0091B4F3 /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -30,7 +27,6 @@ ...@@ -30,7 +27,6 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
961776701CCE75EB0091B4F3 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-bshwisidfobstlbomegqyybbrygh/Build/Products/Debug-iphoneos/Material.framework"; sourceTree = "<absolute>"; };
966F579D1C226BAA009185B7 /* TextField.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TextField.app; sourceTree = BUILT_PRODUCTS_DIR; }; 966F579D1C226BAA009185B7 /* TextField.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TextField.app; sourceTree = BUILT_PRODUCTS_DIR; };
966F57A01C226BAA009185B7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 966F57A01C226BAA009185B7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
966F57A21C226BAA009185B7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; }; 966F57A21C226BAA009185B7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
...@@ -44,7 +40,6 @@ ...@@ -44,7 +40,6 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
961776711CCE75EB0091B4F3 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -54,7 +49,6 @@ ...@@ -54,7 +49,6 @@
966F57941C226BAA009185B7 = { 966F57941C226BAA009185B7 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
961776701CCE75EB0091B4F3 /* Material.framework */,
966F579F1C226BAA009185B7 /* TextField */, 966F579F1C226BAA009185B7 /* TextField */,
966F579E1C226BAA009185B7 /* Products */, 966F579E1C226BAA009185B7 /* Products */,
); );
......
...@@ -94,6 +94,7 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -94,6 +94,7 @@ class ViewController: UIViewController, TextFieldDelegate {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareResignResponderButton()
prepareNameField() prepareNameField()
prepareEmailField() prepareEmailField()
} }
...@@ -103,11 +104,32 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -103,11 +104,32 @@ class ViewController: UIViewController, TextFieldDelegate {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
} }
/// Prepares the resign responder button.
private func prepareResignResponderButton() {
let btn: RaisedButton = RaisedButton()
btn.translatesAutoresizingMaskIntoConstraints = false
btn.addTarget(self, action: #selector(handleResignResponderButton), forControlEvents: .TouchUpInside)
btn.setTitle("Resign", forState: .Normal)
btn.setTitleColor(MaterialColor.blue.base, forState: .Normal)
btn.setTitleColor(MaterialColor.blue.base, forState: .Highlighted)
view.addSubview(btn)
MaterialLayout.alignFromBottomRight(view, child: btn, bottom: 24, right: 24)
MaterialLayout.size(view, child: btn, width: 100, height: 50)
}
/// Handle the resign responder button.
internal func handleResignResponderButton() {
nameField?.resignFirstResponder()
emailField?.resignFirstResponder()
}
/// Prepares the name TextField. /// Prepares the name TextField.
private func prepareNameField() { private func prepareNameField() {
nameField = MTextField() nameField = MTextField()
nameField.placeholder = "Email" nameField.placeholder = "Email"
nameField.detail = "Enter your email address." nameField.detail = "Enter your email address."
nameField.clearButtonMode = .WhileEditing
// The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly. // The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly.
nameField.translatesAutoresizingMaskIntoConstraints = false nameField.translatesAutoresizingMaskIntoConstraints = false
...@@ -116,15 +138,16 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -116,15 +138,16 @@ class ViewController: UIViewController, TextFieldDelegate {
// Size the TextField to the maximum width, less 20 pixels on either side // Size the TextField to the maximum width, less 20 pixels on either side
// with a top margin of 100 pixels. // with a top margin of 100 pixels.
MaterialLayout.alignFromTop(view, child: nameField, top: 100) MaterialLayout.alignFromTop(view, child: nameField, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: nameField, left: 20, right: 20) MaterialLayout.alignToParentHorizontally(view, child: nameField, left: 40, right: 40)
} }
/// Prepares the email TextField. /// Prepares the email TextField.
private func prepareEmailField() { private func prepareEmailField() {
emailField = MTextField(frame: CGRectMake(20, 200, view.bounds.width - 40, 16)) emailField = MTextField(frame: CGRectMake(40, 200, view.bounds.width - 80, 21))
emailField.placeholder = "Email" emailField.placeholder = "Email"
emailField.detail = "Error, incorrect email." emailField.detail = "Error, incorrect email."
emailField.delegate = self emailField.delegate = self
emailField.clearButtonMode = .WhileEditing
view.addSubview(emailField) view.addSubview(emailField)
} }
...@@ -135,30 +158,24 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -135,30 +158,24 @@ class ViewController: UIViewController, TextFieldDelegate {
} }
func textFieldShouldBeginEditing(textField: UITextField) -> Bool { func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
print("Should Begin")
return true return true
} }
func textFieldDidBeginEditing(textField: UITextField) { func textFieldDidBeginEditing(textField: UITextField) {
print("Did Begin")
} }
func textFieldShouldEndEditing(textField: UITextField) -> Bool { func textFieldShouldEndEditing(textField: UITextField) -> Bool {
print("Should End")
return true return true
} }
func textFieldDidEndEditing(textField: UITextField) { func textFieldDidEndEditing(textField: UITextField) {
print("Did End")
} }
func textFieldShouldClear(textField: UITextField) -> Bool { func textFieldShouldClear(textField: UITextField) -> Bool {
print("Should Clear")
return true return true
} }
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
print("Should Change")
return true return true
} }
} }
...@@ -34,6 +34,8 @@ public protocol MTextFieldDelegate : UITextFieldDelegate {} ...@@ -34,6 +34,8 @@ public protocol MTextFieldDelegate : UITextFieldDelegate {}
@IBDesignable @IBDesignable
public class MTextField : UITextField { public class MTextField : UITextField {
public private(set) var animating: Bool = false
/** /**
This property is the same as clipsToBounds. It crops any of the view's This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. contents from bleeding past the view's frame.
...@@ -123,6 +125,21 @@ public class MTextField : UITextField { ...@@ -123,6 +125,21 @@ public class MTextField : UITextField {
/// Divider active state height. /// Divider active state height.
@IBInspectable public var dividerActiveHeight: CGFloat = 2 @IBInspectable public var dividerActiveHeight: CGFloat = 2
/// Sets the divider and tintColor.
@IBInspectable public var dividerColor: UIColor? {
get {
return nil == divider.backgroundColor ? nil : UIColor(CGColor: divider.backgroundColor!)
}
set(value) {
divider.backgroundColor = dividerColor?.CGColor
if let v: UIColor = dividerColor {
tintColor = v
} else {
tintColor = MaterialColor.darkText.dividers
}
}
}
/// The placeholderLabel font value. /// The placeholderLabel font value.
@IBInspectable public override var font: UIFont? { @IBInspectable public override var font: UIFont? {
get { get {
...@@ -141,7 +158,7 @@ public class MTextField : UITextField { ...@@ -141,7 +158,7 @@ public class MTextField : UITextField {
set(value) { set(value) {
placeholderLabel.text = value placeholderLabel.text = value
if let v: String = value { if let v: String = value {
placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor]) placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
} }
} }
} }
...@@ -154,10 +171,10 @@ public class MTextField : UITextField { ...@@ -154,10 +171,10 @@ public class MTextField : UITextField {
@IBInspectable public private(set) lazy var placeholderLabel: UILabel = UILabel(frame: CGRectZero) @IBInspectable public private(set) lazy var placeholderLabel: UILabel = UILabel(frame: CGRectZero)
/// Placeholder textColor. /// Placeholder textColor.
@IBInspectable public var placeholderTextColor: UIColor = MaterialColor.darkText.others { @IBInspectable public var placeholderColor: UIColor = MaterialColor.darkText.others {
didSet { didSet {
if let v: String = placeholder { if let v: String = placeholder {
placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor]) placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
} }
} }
} }
...@@ -174,16 +191,16 @@ public class MTextField : UITextField { ...@@ -174,16 +191,16 @@ public class MTextField : UITextField {
set(value) { set(value) {
detailLabel.text = value detailLabel.text = value
if let v: String = value { if let v: String = value {
detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor]) detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
} }
} }
} }
/// Detail textColor. /// Detail textColor.
@IBInspectable public var detailTextColor: UIColor = MaterialColor.darkText.others { @IBInspectable public var detailColor: UIColor = MaterialColor.darkText.others {
didSet { didSet {
if let v: String = detail { if let v: String = detail {
detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailTextColor]) detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor])
} }
} }
} }
...@@ -215,7 +232,7 @@ public class MTextField : UITextField { ...@@ -215,7 +232,7 @@ public class MTextField : UITextField {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if !editing { if !editing && !animating {
layoutPlaceholderLabel() layoutPlaceholderLabel()
layoutDetailLabel() layoutDetailLabel()
} }
...@@ -329,7 +346,8 @@ public class MTextField : UITextField { ...@@ -329,7 +346,8 @@ public class MTextField : UITextField {
} else if CGAffineTransformIsIdentity(placeholderLabel.transform) { } else if CGAffineTransformIsIdentity(placeholderLabel.transform) {
placeholderLabel.frame = bounds placeholderLabel.frame = bounds
placeholderLabel.transform = CGAffineTransformScale(placeholderLabel.transform, 0.75, 0.75) placeholderLabel.transform = CGAffineTransformScale(placeholderLabel.transform, 0.75, 0.75)
placeholderLabel.frame.origin = CGPointMake(0, -24) placeholderLabel.frame.origin.x = 0
placeholderLabel.frame.origin.y = -21
} }
} }
...@@ -353,25 +371,34 @@ public class MTextField : UITextField { ...@@ -353,25 +371,34 @@ public class MTextField : UITextField {
/// The animation for the placeholder when editing begins. /// The animation for the placeholder when editing begins.
public func placeholderEditingDidBeginAnimation() { public func placeholderEditingDidBeginAnimation() {
placeholderLabel.textColor = placeholderTextColor
if CGAffineTransformIsIdentity(placeholderLabel.transform) { if CGAffineTransformIsIdentity(placeholderLabel.transform) {
animating = true
UIView.animateWithDuration(0.15, animations: { [weak self] in UIView.animateWithDuration(0.15, animations: { [weak self] in
if let s: MTextField = self { if let v: MTextField = self {
s.placeholderLabel.transform = CGAffineTransformScale(s.placeholderLabel.transform, 0.75, 0.75) v.placeholderLabel.transform = CGAffineTransformMakeScale(0.75, 0.75)
s.placeholderLabel.frame.origin = CGPointMake(0, -24) v.placeholderLabel.frame.origin.x = 0
v.placeholderLabel.frame.origin.y = -21
}
}) { [weak self] _ in
self?.animating = false
} }
})
} }
} }
/// The animation for the placeholder when editing ends. /// The animation for the placeholder when editing ends.
public func placeholderEditingDidEndAnimation() { public func placeholderEditingDidEndAnimation() {
if !CGAffineTransformIsIdentity(placeholderLabel.transform) {
animating = true
UIView.animateWithDuration(0.15, animations: { [weak self] in UIView.animateWithDuration(0.15, animations: { [weak self] in
if let s: MTextField = self { if let v: MTextField = self {
s.placeholderLabel.transform = CGAffineTransformIdentity v.placeholderLabel.transform = CGAffineTransformIdentity
s.placeholderLabel.frame = s.bounds v.placeholderLabel.frame.origin.x = 0
v.placeholderLabel.frame.origin.y = 0
}
}) { [weak self] _ in
self?.animating = false
}
} }
})
} }
/// Prepares the divider. /// Prepares the divider.
...@@ -383,14 +410,14 @@ public class MTextField : UITextField { ...@@ -383,14 +410,14 @@ public class MTextField : UITextField {
/// Prepares the placeholderLabel. /// Prepares the placeholderLabel.
private func preparePlaceholderLabel() { private func preparePlaceholderLabel() {
placeholderLabel.font = font placeholderLabel.font = font
placeholderTextColor = MaterialColor.darkText.others placeholderColor = MaterialColor.darkText.others
addSubview(placeholderLabel) addSubview(placeholderLabel)
} }
/// Prepares the detailLabel. /// Prepares the detailLabel.
private func prepareDetailLabel() { private func prepareDetailLabel() {
detailLabel.font = RobotoFont.regularWithSize(12) detailLabel.font = RobotoFont.regularWithSize(12)
detailTextColor = MaterialColor.darkText.others detailColor = MaterialColor.darkText.others
addSubview(detailLabel) addSubview(detailLabel)
} }
......
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