Commit b7519596 by Daniel Dahan

updated TextField component

parent f853a5f9
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
964F5D0C1C24823400DD950F /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 964F5D0B1C24823400DD950F /* MaterialKit.framework */; };
964F5D0D1C24823400DD950F /* MaterialKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 964F5D0B1C24823400DD950F /* MaterialKit.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 */; };
...@@ -20,6 +22,7 @@ ...@@ -20,6 +22,7 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
964F5D0D1C24823400DD950F /* MaterialKit.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -27,6 +30,7 @@ ...@@ -27,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
964F5D0B1C24823400DD950F /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MaterialKit.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-anypxbsecgdqqxevbavirvnffqxd/Build/Products/Debug-iphoneos/MaterialKit.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>"; };
...@@ -40,6 +44,7 @@ ...@@ -40,6 +44,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
964F5D0C1C24823400DD950F /* MaterialKit.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -49,6 +54,7 @@ ...@@ -49,6 +54,7 @@
966F57941C226BAA009185B7 = { 966F57941C226BAA009185B7 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
964F5D0B1C24823400DD950F /* MaterialKit.framework */,
966F579F1C226BAA009185B7 /* TextField */, 966F579F1C226BAA009185B7 /* TextField */,
966F579E1C226BAA009185B7 /* Products */, 966F579E1C226BAA009185B7 /* Products */,
); );
......
...@@ -52,6 +52,7 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -52,6 +52,7 @@ class ViewController: UIViewController, TextFieldDelegate {
titleField.titleLabel!.font = RobotoFont.mediumWithSize(12) titleField.titleLabel!.font = RobotoFont.mediumWithSize(12)
titleField.titleLabelNormalColor = MaterialColor.grey.lighten1 titleField.titleLabelNormalColor = MaterialColor.grey.lighten1
titleField.titleLabelHighlightedColor = MaterialColor.blue.accent3 titleField.titleLabelHighlightedColor = MaterialColor.blue.accent3
titleField.clearButtonMode = .WhileEditing
view.addSubview(titleField) view.addSubview(titleField)
} }
...@@ -69,6 +70,7 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -69,6 +70,7 @@ class ViewController: UIViewController, TextFieldDelegate {
descriptionField.titleLabel!.font = RobotoFont.mediumWithSize(12) descriptionField.titleLabel!.font = RobotoFont.mediumWithSize(12)
descriptionField.titleLabelNormalColor = MaterialColor.grey.lighten1 descriptionField.titleLabelNormalColor = MaterialColor.grey.lighten1
descriptionField.titleLabelHighlightedColor = MaterialColor.blue.accent3 descriptionField.titleLabelHighlightedColor = MaterialColor.blue.accent3
descriptionField.clearButtonMode = .WhileEditing
view.addSubview(descriptionField) view.addSubview(descriptionField)
} }
......
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'MK' s.name = 'MK'
s.version = '1.25.5' s.version = '1.25.6'
s.license = { :type => "AGPL-3.0", :file => "LICENSE" } s.license = { :type => "AGPL-3.0", :file => "LICENSE" }
s.summary = 'Beautiful Material Design in Swift.' s.summary = 'A beautiful Material Design framework in Swift.'
s.homepage = 'http://materialkit.io' s.homepage = 'http://materialkit.io'
s.social_media_url = 'https://www.facebook.com/graphkit' s.social_media_url = 'https://www.facebook.com/graphkit'
s.authors = { 'CosmicMind, Inc.' => 'support@cosmicmind.io' } s.authors = { 'CosmicMind, Inc.' => 'support@cosmicmind.io' }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.25.5</string> <string>1.25.6</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -68,9 +68,9 @@ public extension MaterialAnimation { ...@@ -68,9 +68,9 @@ public extension MaterialAnimation {
} }
/** /**
:name: rotation :name: rotate
*/ */
public static func rotation(rotations: Double = 1, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func rotate(rotations: Double = 1, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation: CABasicAnimation = CABasicAnimation() let animation: CABasicAnimation = CABasicAnimation()
animation.keyPath = "transform.rotation" animation.keyPath = "transform.rotation"
animation.byValue = (M_PI * 2 * rotations) as NSNumber animation.byValue = (M_PI * 2 * rotations) as NSNumber
...@@ -84,9 +84,9 @@ public extension MaterialAnimation { ...@@ -84,9 +84,9 @@ public extension MaterialAnimation {
} }
/** /**
:name: rotationX :name: rotateX
*/ */
public static func rotationX(rotations: Double = 1, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func rotateX(rotations: Double = 1, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation: CABasicAnimation = CABasicAnimation() let animation: CABasicAnimation = CABasicAnimation()
animation.keyPath = "transform.rotation.x" animation.keyPath = "transform.rotation.x"
animation.byValue = (M_PI_4 * rotations) as NSNumber animation.byValue = (M_PI_4 * rotations) as NSNumber
...@@ -100,9 +100,9 @@ public extension MaterialAnimation { ...@@ -100,9 +100,9 @@ public extension MaterialAnimation {
} }
/** /**
:name: rotationY :name: rotateY
*/ */
public static func rotationY(rotations: Double = 1, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func rotateY(rotations: Double = 1, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation: CABasicAnimation = CABasicAnimation() let animation: CABasicAnimation = CABasicAnimation()
animation.keyPath = "transform.rotation.y" animation.keyPath = "transform.rotation.y"
animation.byValue = (M_PI_4 * rotations) as NSNumber animation.byValue = (M_PI_4 * rotations) as NSNumber
...@@ -116,9 +116,9 @@ public extension MaterialAnimation { ...@@ -116,9 +116,9 @@ public extension MaterialAnimation {
} }
/** /**
:name: rotationZ :name: rotateZ
*/ */
public static func rotationZ(rotations: Double = 1, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func rotateZ(rotations: Double = 1, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation: CABasicAnimation = CABasicAnimation() let animation: CABasicAnimation = CABasicAnimation()
animation.keyPath = "transform.rotation.z" animation.keyPath = "transform.rotation.z"
animation.byValue = (M_PI_4 * rotations) as NSNumber animation.byValue = (M_PI_4 * rotations) as NSNumber
...@@ -196,9 +196,9 @@ public extension MaterialAnimation { ...@@ -196,9 +196,9 @@ public extension MaterialAnimation {
} }
/** /**
:name: translation :name: translate
*/ */
public static func translation(translation: CGSize, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func translate(translation: CGSize, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation: CABasicAnimation = CABasicAnimation() let animation: CABasicAnimation = CABasicAnimation()
animation.keyPath = "transform.translation" animation.keyPath = "transform.translation"
animation.toValue = NSValue(CGSize: translation) animation.toValue = NSValue(CGSize: translation)
...@@ -212,9 +212,9 @@ public extension MaterialAnimation { ...@@ -212,9 +212,9 @@ public extension MaterialAnimation {
} }
/** /**
:name: translationX :name: translateX
*/ */
public static func translationX(translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func translateX(translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation: CABasicAnimation = CABasicAnimation() let animation: CABasicAnimation = CABasicAnimation()
animation.keyPath = "transform.translation.x" animation.keyPath = "transform.translation.x"
animation.toValue = translation as NSNumber animation.toValue = translation as NSNumber
...@@ -228,9 +228,9 @@ public extension MaterialAnimation { ...@@ -228,9 +228,9 @@ public extension MaterialAnimation {
} }
/** /**
:name: translationY :name: translateY
*/ */
public static func translationY(translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func translateY(translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation: CABasicAnimation = CABasicAnimation() let animation: CABasicAnimation = CABasicAnimation()
animation.keyPath = "transform.translation.y" animation.keyPath = "transform.translation.y"
animation.toValue = translation as NSNumber animation.toValue = translation as NSNumber
...@@ -244,9 +244,9 @@ public extension MaterialAnimation { ...@@ -244,9 +244,9 @@ public extension MaterialAnimation {
} }
/** /**
:name: translationZ :name: translateZ
*/ */
public static func translationZ(translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func translateZ(translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation: CABasicAnimation = CABasicAnimation() let animation: CABasicAnimation = CABasicAnimation()
animation.keyPath = "transform.translation.z" animation.keyPath = "transform.translation.z"
animation.toValue = translation as NSNumber animation.toValue = translation as NSNumber
......
...@@ -22,9 +22,61 @@ public protocol TextFieldDelegate : UITextFieldDelegate {} ...@@ -22,9 +22,61 @@ public protocol TextFieldDelegate : UITextFieldDelegate {}
public class TextField : UITextField { public class TextField : UITextField {
/** /**
:name: count :name: backgroundColor
*/ */
private var count: Int? public override var backgroundColor: UIColor? {
didSet {
layer.backgroundColor = backgroundColor?.CGColor
}
}
/**
:name: x
*/
public var x: CGFloat {
get {
return layer.frame.origin.x
}
set(value) {
layer.frame.origin.x = value
}
}
/**
:name: y
*/
public var y: CGFloat {
get {
return layer.frame.origin.y
}
set(value) {
layer.frame.origin.y = value
}
}
/**
:name: width
*/
public var width: CGFloat {
get {
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
}
}
/**
:name: height
*/
public var height: CGFloat {
get {
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
}
}
/** /**
:name: titleLabelNormalColor :name: titleLabelNormalColor
...@@ -50,9 +102,64 @@ public class TextField : UITextField { ...@@ -50,9 +102,64 @@ public class TextField : UITextField {
} }
/** /**
:name: bottomBorderEnabled :name: layoutSublayersOfLayer
*/ */
public var bottomBorderEnabled: Bool = true public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
}
}
/**
:name: actionForLayer
*/
public override func actionForLayer(layer: CALayer, forKey event: String) -> CAAction? {
return nil
}
/**
:name: animate
*/
public func animate(animation: CAAnimation) {
animation.delegate = self
if let a: CABasicAnimation = animation as? CABasicAnimation {
a.fromValue = (nil == layer.presentationLayer() ? layer : layer.presentationLayer() as! CALayer).valueForKeyPath(a.keyPath!)
}
if let a: CAPropertyAnimation = animation as? CAPropertyAnimation {
layer.addAnimation(a, forKey: a.keyPath!)
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
layer.addAnimation(a, forKey: nil)
} else if let a: CATransition = animation as? CATransition {
layer.addAnimation(a, forKey: kCATransition)
}
}
/**
:name: animationDidStart
*/
public override func animationDidStart(anim: CAAnimation) {
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStart?(anim)
}
/**
:name: animationDidStop
*/
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation {
MaterialAnimation.animationDisabled {
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
}
}
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
layer.removeAnimationForKey(a.keyPath!)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
}
/** /**
:name: init :name: init
...@@ -88,58 +195,30 @@ public class TextField : UITextField { ...@@ -88,58 +195,30 @@ public class TextField : UITextField {
:name: textFieldDidBegin :name: textFieldDidBegin
*/ */
internal func textFieldDidBegin(textField: TextField) { internal func textFieldDidBegin(textField: TextField) {
count = text?.utf16.count
titleLabel?.text = placeholder titleLabel?.text = placeholder
titleLabel?.textColor = 0 == count ? titleLabelNormalColor : titleLabelHighlightedColor titleLabel?.textColor = 0 == text?.utf16.count ? titleLabelNormalColor : titleLabelHighlightedColor
} }
/** /**
:name: textFieldDidChange :name: textFieldDidChange
*/ */
internal func textFieldDidChange(textField: TextField) { internal func textFieldDidChange(textField: TextField) {
if 0 == count && 1 == text?.utf16.count { if 0 < text?.utf16.count {
if let v: UILabel = titleLabel { showTitleLabel()
v.hidden = false
UIView.animateWithDuration(0.25, animations: {
v.alpha = 1
v.frame.origin.y = -v.frame.height
})
titleLabel?.textColor = titleLabelHighlightedColor titleLabel?.textColor = titleLabelHighlightedColor
} } else if 0 == text?.utf16.count {
} else if 1 == count && 0 == text?.utf16.count { hideTitleLabel()
if let v: UILabel = titleLabel {
UIView.animateWithDuration(0.25, animations: {
v.alpha = 0
v.frame.origin.y = -v.frame.height + 4
}) { _ in
v.hidden = true
}
} }
} }
count = text?.utf16.count
}
/** /**
:name: textFieldDidEnd :name: textFieldDidEnd
*/ */
internal func textFieldDidEnd(textField: TextField) { internal func textFieldDidEnd(textField: TextField) {
if 0 < count { if 0 < text?.utf16.count {
if let v: UILabel = titleLabel { showTitleLabel()
v.hidden = false } else if 0 == text?.utf16.count {
UIView.animateWithDuration(0.25, animations: { hideTitleLabel()
v.alpha = 1
v.frame.origin.y = -v.frame.height
})
}
} else if 0 == count {
if let v: UILabel = titleLabel {
UIView.animateWithDuration(0.25, animations: {
v.alpha = 0
v.frame.origin.y = -v.frame.height + 4
}) { _ in
v.hidden = true
}
}
} }
titleLabel?.textColor = titleLabelNormalColor titleLabel?.textColor = titleLabelNormalColor
} }
...@@ -162,4 +241,31 @@ public class TextField : UITextField { ...@@ -162,4 +241,31 @@ public class TextField : UITextField {
addTarget(self, action: "textFieldDidEnd:", forControlEvents: .EditingDidEnd) addTarget(self, action: "textFieldDidEnd:", forControlEvents: .EditingDidEnd)
} }
} }
/**
:name: showTitleLabel
*/
private func showTitleLabel() {
if let v: UILabel = titleLabel {
v.hidden = false
UIView.animateWithDuration(0.25, animations: {
v.alpha = 1
v.frame.origin.y = -v.frame.height
})
}
}
/**
:name: hideTitleLabel
*/
private func hideTitleLabel() {
if let v: UILabel = titleLabel {
UIView.animateWithDuration(0.25, animations: {
v.alpha = 0
v.frame.origin.y = -v.frame.height + 4
}) { _ in
v.hidden = true
}
}
}
} }
\ No newline at end of file
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