Commit 867fc755 by Daniel Dahan

updated default colors and sizes, and added help properties to set the values when active

parent 541aaec7
......@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
9658F1F01CD3C0EA00B902C1 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F1EF1CD3C0EA00B902C1 /* Material.framework */; };
9658F1F11CD3C0EA00B902C1 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F1EF1CD3C0EA00B902C1 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
966F57A11C226BAA009185B7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57A01C226BAA009185B7 /* AppDelegate.swift */; };
966F57A31C226BAA009185B7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57A21C226BAA009185B7 /* ViewController.swift */; };
966F57A81C226BAA009185B7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 966F57A71C226BAA009185B7 /* Assets.xcassets */; };
......@@ -20,6 +22,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
9658F1F11CD3C0EA00B902C1 /* Material.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -27,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
9658F1EF1CD3C0EA00B902C1 /* 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; };
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>"; };
......@@ -40,6 +44,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9658F1F01CD3C0EA00B902C1 /* Material.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -49,6 +54,7 @@
966F57941C226BAA009185B7 = {
isa = PBXGroup;
children = (
9658F1EF1CD3C0EA00B902C1 /* Material.framework */,
966F579F1C226BAA009185B7 /* TextField */,
966F579E1C226BAA009185B7 /* Products */,
);
......
......@@ -99,6 +99,11 @@ class ViewController: UIViewController, TextFieldDelegate {
prepareEmailField()
}
/// Programmatic update for the textField as it rotates.
override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
emailField.width = view.bounds.height
}
/// General preparation statements.
private func prepareView() {
view.backgroundColor = MaterialColor.white
......@@ -130,6 +135,10 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField.placeholder = "Email"
nameField.detail = "Enter your email address."
nameField.clearButtonMode = .WhileEditing
nameField.textAlignment = .Center
nameField.text = "daniel@dahan"
nameField.backgroundColor = MaterialColor.green.accent1
nameField.placeholderLabel.backgroundColor = MaterialColor.green.accent3
// The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly.
nameField.translatesAutoresizingMaskIntoConstraints = false
......@@ -143,7 +152,7 @@ class ViewController: UIViewController, TextFieldDelegate {
/// Prepares the email TextField.
private func prepareEmailField() {
emailField = MTextField(frame: CGRectMake(40, 200, view.bounds.width - 80, 21))
emailField = MTextField(frame: CGRectMake(40, 200, view.bounds.width - 80, 32))
emailField.placeholder = "Email"
emailField.detail = "Error, incorrect email."
emailField.delegate = self
......
......@@ -126,19 +126,7 @@ public class MTextField : UITextField {
@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
}
}
}
@IBInspectable public var dividerColor: UIColor = MaterialColor.darkText.dividers
/// The placeholderLabel font value.
@IBInspectable public override var font: UIFont? {
......@@ -171,13 +159,10 @@ public class MTextField : UITextField {
@IBInspectable public private(set) lazy var placeholderLabel: UILabel = UILabel(frame: CGRectZero)
/// Placeholder textColor.
@IBInspectable public var placeholderColor: UIColor = MaterialColor.darkText.others {
didSet {
if let v: String = placeholder {
placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
}
}
}
@IBInspectable public var placeholderColor: UIColor = MaterialColor.darkText.others
/// Placeholder active textColor.
@IBInspectable public var placeholderActiveColor: UIColor = MaterialColor.blue.base
/// The detailLabel UILabel that is displayed.
@IBInspectable public private(set) lazy var detailLabel: UILabel = UILabel(frame: CGRectZero)
......@@ -191,17 +176,22 @@ public class MTextField : UITextField {
set(value) {
detailLabel.text = value
if let v: String = value {
detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor])
}
}
}
/// Detail textColor.
@IBInspectable public var detailColor: UIColor = MaterialColor.darkText.others {
didSet {
if let v: String = detail {
detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor])
@IBInspectable public var detailColor: UIColor = MaterialColor.darkText.others
/// Handles the textAlignment of the placeholderLabel.
public override var textAlignment: NSTextAlignment {
get {
return placeholderLabel.textAlignment
}
set(value) {
super.textAlignment = value
placeholderLabel.textAlignment = value
}
}
......@@ -247,6 +237,11 @@ public class MTextField : UITextField {
}
}
/// Default size when using AutoLayout.
public override func intrinsicContentSize() -> CGSize {
return CGSizeMake(width, 32)
}
/**
A method that accepts CAAnimation objects and executes them on the
view's backing layer.
......@@ -310,10 +305,8 @@ public class MTextField : UITextField {
/// Handles the text editing did end state.
public func handleEditingDidEnd() {
dividerEditingDidEndAnimation()
if true == text?.isEmpty {
placeholderEditingDidEndAnimation()
}
}
/**
Prepares the view instance when intialized. When subclassing,
......@@ -336,7 +329,7 @@ public class MTextField : UITextField {
/// Layout the divider.
public func layoutDivider() {
divider.frame = CGRectMake(0, height + 8, width, dividerHeight)
divider.frame = CGRectMake(0, height, width, dividerHeight)
}
/// Layout the placeholderLabel.
......@@ -345,28 +338,29 @@ public class MTextField : UITextField {
placeholderLabel.frame = bounds
} else if CGAffineTransformIsIdentity(placeholderLabel.transform) {
placeholderLabel.frame = bounds
placeholderLabel.transform = CGAffineTransformScale(placeholderLabel.transform, 0.75, 0.75)
placeholderLabel.transform = CGAffineTransformMakeScale(0.75, 0.75)
placeholderLabel.frame.origin.x = 0
placeholderLabel.frame.origin.y = -21
placeholderLabel.frame.origin.y = -placeholderLabel.frame.size.height
placeholderLabel.textColor = placeholderColor
}
}
/// Layout the detailLabel.
public func layoutDetailLabel() {
detailLabel.frame = CGRectMake(0, height + 16, width, 12)
detailLabel.frame = CGRectMake(0, height + 8, width, 12)
detailLabel.sizeToFit()
}
/// The animation for the divider when editing begins.
public func dividerEditingDidBeginAnimation() {
divider.frame.size.height = dividerActiveHeight
divider.backgroundColor = MaterialColor.blue.base.CGColor
divider.backgroundColor = placeholderActiveColor.CGColor
}
/// The animation for the divider when editing ends.
public func dividerEditingDidEndAnimation() {
divider.frame.size.height = dividerHeight
divider.backgroundColor = MaterialColor.darkText.dividers.CGColor
divider.backgroundColor = dividerColor.CGColor
}
/// The animation for the placeholder when editing begins.
......@@ -377,27 +371,33 @@ public class MTextField : UITextField {
if let v: MTextField = self {
v.placeholderLabel.transform = CGAffineTransformMakeScale(0.75, 0.75)
v.placeholderLabel.frame.origin.x = 0
v.placeholderLabel.frame.origin.y = -21
v.placeholderLabel.frame.origin.y = -v.placeholderLabel.frame.size.height
v.placeholderLabel.textColor = v.placeholderActiveColor
}
}) { [weak self] _ in
self?.animating = false
}
} else if editing {
placeholderLabel.textColor = placeholderActiveColor
}
}
/// The animation for the placeholder when editing ends.
public func placeholderEditingDidEndAnimation() {
if !CGAffineTransformIsIdentity(placeholderLabel.transform) {
if !CGAffineTransformIsIdentity(placeholderLabel.transform) && true == text?.isEmpty {
animating = true
UIView.animateWithDuration(0.15, animations: { [weak self] in
if let v: MTextField = self {
v.placeholderLabel.transform = CGAffineTransformIdentity
v.placeholderLabel.frame.origin.x = 0
v.placeholderLabel.frame.origin.y = 0
v.placeholderLabel.textColor = v.placeholderColor
}
}) { [weak self] _ in
self?.animating = false
}
} else if !editing {
placeholderLabel.textColor = placeholderColor
}
}
......@@ -409,7 +409,6 @@ public class MTextField : UITextField {
/// Prepares the placeholderLabel.
private func preparePlaceholderLabel() {
placeholderLabel.font = font
placeholderColor = MaterialColor.darkText.others
addSubview(placeholderLabel)
}
......
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