Commit 511b51ba by Daniel Dahan

updated TextView to handle set text with titleLabel

parent d230c6b3
......@@ -3,79 +3,79 @@
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-29@2x-1.png",
"filename" : "MaterialKit-Icon-29@2x-1.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-29@3x.png",
"filename" : "MaterialKit-Icon-29@3x.png",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-40@2x.png",
"filename" : "MaterialKit-Icon-40@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-40@3x.png",
"filename" : "MaterialKit-Icon-40@3x.png",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-60@2x.png",
"filename" : "MaterialKit-Icon-60@2x.png",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-60@3x.png",
"filename" : "MaterialKit-Icon-60@3x.png",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-29.png",
"filename" : "MaterialKit-Icon-29.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-29@2x.png",
"filename" : "MaterialKit-Icon-29@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-40.png",
"filename" : "MaterialKit-Icon-40.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-40@2x-1.png",
"filename" : "MaterialKit-Icon-40@2x-1.png",
"scale" : "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-76.png",
"filename" : "MaterialKit-Icon-76.png",
"scale" : "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-76@2x.png",
"filename" : "MaterialKit-Icon-76@2x.png",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-83.5@2x.png",
"filename" : "MaterialKit-Icon-83.5@2x.png",
"scale" : "2x"
}
],
......
......@@ -11,8 +11,6 @@
961F5F2C1C1726A300C94B43 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961F5F2B1C1726A300C94B43 /* ViewController.swift */; };
961F5F311C1726A300C94B43 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 961F5F301C1726A300C94B43 /* Assets.xcassets */; };
961F5F341C1726A300C94B43 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 961F5F321C1726A300C94B43 /* LaunchScreen.storyboard */; };
96607D8B1C3F5795008D47D8 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96607D8A1C3F5795008D47D8 /* MaterialKit.framework */; };
96607D8C1C3F5795008D47D8 /* MaterialKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96607D8A1C3F5795008D47D8 /* MaterialKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -22,7 +20,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
96607D8C1C3F5795008D47D8 /* MaterialKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -36,7 +33,6 @@
961F5F301C1726A300C94B43 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
961F5F331C1726A300C94B43 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
961F5F351C1726A300C94B43 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
96607D8A1C3F5795008D47D8 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MaterialKit.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-gdulktuccbcfwbdfadtpxkworhyc/Build/Products/Debug-iphoneos/MaterialKit.framework"; sourceTree = "<absolute>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -44,7 +40,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
96607D8B1C3F5795008D47D8 /* MaterialKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -54,7 +49,6 @@
961F5F1D1C1726A300C94B43 = {
isa = PBXGroup;
children = (
96607D8A1C3F5795008D47D8 /* MaterialKit.framework */,
961F5F281C1726A300C94B43 /* MaterialLayout */,
961F5F271C1726A300C94B43 /* Products */,
);
......
......@@ -3,79 +3,79 @@
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-29@2x-1.png",
"filename" : "MaterialKit-Icon-29@2x-1.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-29@3x.png",
"filename" : "MaterialKit-Icon-29@3x.png",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-40@2x.png",
"filename" : "MaterialKit-Icon-40@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-40@3x.png",
"filename" : "MaterialKit-Icon-40@3x.png",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-60@2x.png",
"filename" : "MaterialKit-Icon-60@2x.png",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "MaterialKit_Icons_Set_Icon-60@3x.png",
"filename" : "MaterialKit-Icon-60@3x.png",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-29.png",
"filename" : "MaterialKit-Icon-29.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-29@2x.png",
"filename" : "MaterialKit-Icon-29@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-40.png",
"filename" : "MaterialKit-Icon-40.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-40@2x-1.png",
"filename" : "MaterialKit-Icon-40@2x-1.png",
"scale" : "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-76.png",
"filename" : "MaterialKit-Icon-76.png",
"scale" : "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-76@2x.png",
"filename" : "MaterialKit-Icon-76@2x.png",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "MaterialKit_Icons_Set_Icon-83.5@2x.png",
"filename" : "MaterialKit-Icon-83.5@2x.png",
"scale" : "2x"
}
],
......
......@@ -31,8 +31,6 @@
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
......
......@@ -29,7 +29,9 @@
*/
/**
MaterialLayout
MaterialLayout is an excellent tool to ease the use of AutoLayout. The following
examples demonstrate laying out a collection of UILabel objects, both vertically
and horizontally.
*/
import UIKit
......@@ -83,8 +85,10 @@ class ViewController: UIViewController {
// Align the labels horizontally with an equal width.
MaterialLayout.alignToParentHorizontally(view, children: children, left: 30, right: 30, spacing: 30)
// Individually set the labels' vertical alignment.
// If this is left out, the intrinsic value is used for the view.
/*
Individually set the labels' vertical alignment.
If this is left out, the intrinsic value is used for the view.
*/
for v in children {
MaterialLayout.alignToParentVertically(view, child: v, top: 100, bottom: 100)
}
......@@ -131,8 +135,10 @@ class ViewController: UIViewController {
// Align the labels vertically with an equal height.
MaterialLayout.alignToParentVertically(view, children: children, top: 100, bottom: 100, spacing: 100)
// Individually set the labels' horizontal alignment.
// If this is left out, the intrinsic value is used for the view.
/*
Individually set the labels' horizontal alignment.
If this is left out, the intrinsic value is used for the view.
*/
for v in children {
MaterialLayout.alignToParentHorizontally(view, child: v, left: 100, right: 100)
}
......
......@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
96607DE31C42C872008D47D8 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96607DE21C42C872008D47D8 /* MaterialKit.framework */; };
96607DE41C42C872008D47D8 /* MaterialKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96607DE21C42C872008D47D8 /* MaterialKit.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 = (
96607DE41C42C872008D47D8 /* MaterialKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -27,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
96607DE21C42C872008D47D8 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MaterialKit.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-gdulktuccbcfwbdfadtpxkworhyc/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; };
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 = (
96607DE31C42C872008D47D8 /* MaterialKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -49,6 +54,7 @@
966F57941C226BAA009185B7 = {
isa = PBXGroup;
children = (
96607DE21C42C872008D47D8 /* MaterialKit.framework */,
966F579F1C226BAA009185B7 /* TextField */,
966F579E1C226BAA009185B7 /* Products */,
);
......
......@@ -65,6 +65,7 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField.titleLabelColor = MaterialColor.grey.lighten1
nameField.titleLabelActiveColor = MaterialColor.blue.accent3
nameField.clearButtonMode = .WhileEditing
nameField.text = "Hello"
view.addSubview(nameField)
}
......
......@@ -47,7 +47,7 @@ class ViewController: UIViewController, TextDelegate, TextViewDelegate {
func prepareTextView() {
let layoutManager: NSLayoutManager = NSLayoutManager()
let textContainer = NSTextContainer(size: view.bounds.size)
let textContainer: NSTextContainer = NSTextContainer(size: view.bounds.size)
layoutManager.addTextContainer(textContainer)
text.delegate = self
......@@ -55,8 +55,6 @@ class ViewController: UIViewController, TextDelegate, TextViewDelegate {
textView = TextView(textContainer: textContainer)
textView.delegate = self
textView.editable = true
textView.selectable = true
textView.font = RobotoFont.regular
textView.placeholderLabel = UILabel()
......
Pod::Spec.new do |s|
s.name = 'MK'
s.version = '1.27.12'
s.version = '1.27.13'
s.license = 'BSD'
s.summary = 'Beautiful Material Design in Swift.'
s.homepage = 'http://materialkit.io'
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -250,7 +250,9 @@ public class TextField : UITextField {
public var titleLabelColor: UIColor? {
didSet {
titleLabel?.textColor = titleLabelColor
bottomBorderLayer.backgroundColor = titleLabelColor?.CGColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.titleLabelColor?.CGColor
}
}
}
......@@ -279,11 +281,15 @@ public class TextField : UITextField {
public var detailLabelHidden: Bool = false {
didSet {
if detailLabelHidden {
bottomBorderLayer.backgroundColor = editing ? titleLabelActiveColor?.CGColor : titleLabelColor?.CGColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.editing ? self.titleLabelActiveColor?.CGColor : self.titleLabelColor?.CGColor
}
hideDetailLabel()
} else {
detailLabel?.textColor = detailLabelActiveColor
bottomBorderLayer.backgroundColor = detailLabelActiveColor?.CGColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.detailLabelActiveColor?.CGColor
}
showDetailLabel()
}
}
......@@ -410,11 +416,15 @@ public class TextField : UITextField {
if 0 == text?.utf16.count {
titleLabel?.textColor = titleLabelColor
bottomBorderLayer.backgroundColor = titleLabelColor?.CGColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.titleLabelColor?.CGColor
}
detailLabelHidden = true
} else {
titleLabel?.textColor = titleLabelActiveColor
bottomBorderLayer.backgroundColor = detailLabelHidden ? titleLabelActiveColor?.CGColor : detailLabelActiveColor?.CGColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.detailLabelHidden ? self.titleLabelActiveColor?.CGColor : self.detailLabelActiveColor?.CGColor
}
}
}
......@@ -423,7 +433,9 @@ public class TextField : UITextField {
if 0 < text?.utf16.count {
showTitleLabel()
titleLabel?.textColor = titleLabelActiveColor
bottomBorderLayer.backgroundColor = detailLabelHidden ? titleLabelActiveColor?.CGColor : detailLabelActiveColor?.CGColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.detailLabelHidden ? self.titleLabelActiveColor?.CGColor : self.detailLabelActiveColor?.CGColor
}
} else if 0 == text?.utf16.count {
hideTitleLabel()
detailLabelHidden = true
......@@ -438,7 +450,9 @@ public class TextField : UITextField {
hideTitleLabel()
}
titleLabel?.textColor = titleLabelColor
bottomBorderLayer.backgroundColor = detailLabelHidden ? titleLabelColor?.CGColor : detailLabelActiveColor?.CGColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.detailLabelHidden ? self.titleLabelColor?.CGColor : self.detailLabelActiveColor?.CGColor
}
}
/// Manages the layout for the shape of the view instance.
......
......@@ -419,22 +419,13 @@ public class TextView: UITextView {
/// Notification handler for when text editing began.
internal func handleTextViewTextDidBegin() {
if let v: UILabel = titleLabel {
if v.hidden {
let h: CGFloat = v.font.pointSize
v.frame = CGRectMake(0, -h, bounds.width, h)
v.text = placeholderLabel?.text
if 0 == text?.utf16.count {
v.textColor = titleLabelColor
} else {
v.textColor = titleLabelActiveColor
}
}
}
prepareTitleLabelForAnimation()
}
/// Notification handler for when text changed.
internal func handleTextViewTextDidChange() {
prepareTitleLabelForAnimation()
if let p = placeholderLabel {
p.hidden = !(true == text?.isEmpty)
}
......@@ -501,17 +492,35 @@ public class TextView: UITextView {
v.hidden = true
v.alpha = 0
}
titleLabel?.text = placeholderLabel?.text
addSubview(v)
}
}
/// Parepares the titleLabel before it animates.
private func prepareTitleLabelForAnimation() {
if let v: UILabel = titleLabel {
if v.hidden {
let h: CGFloat = v.font.pointSize
v.frame = CGRectMake(0, -h, bounds.width, h)
if let s: String = placeholderLabel?.text {
v.text = s
}
if 0 == text?.utf16.count {
v.textColor = titleLabelColor
} else {
v.textColor = titleLabelActiveColor
}
}
}
}
/// Shows and animates the titleLabel property.
private func showTitleLabel() {
if let v: UILabel = titleLabel {
v.hidden = false
UIView.animateWithDuration(0.25, animations: {
v.alpha = 1
print(v.frame)
v.frame.origin.y = -v.frame.height - 4
})
}
......
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