Commit bc0d00c7 by Daniel Dahan

initil reorganization of TextView

parent 53092d1d
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
960590221C388FD800691E88 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 960590211C388FD800691E88 /* ViewController.swift */; }; 960590221C388FD800691E88 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 960590211C388FD800691E88 /* ViewController.swift */; };
960590271C388FD800691E88 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 960590261C388FD800691E88 /* Assets.xcassets */; }; 960590271C388FD800691E88 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 960590261C388FD800691E88 /* Assets.xcassets */; };
9605902A1C388FD800691E88 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 960590281C388FD800691E88 /* LaunchScreen.storyboard */; }; 9605902A1C388FD800691E88 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 960590281C388FD800691E88 /* LaunchScreen.storyboard */; };
96977E161CBD7F59000BEFC4 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96977E151CBD7F59000BEFC4 /* Material.framework */; };
96977E171CBD7F59000BEFC4 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96977E151CBD7F59000BEFC4 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
...@@ -20,6 +22,7 @@ ...@@ -20,6 +22,7 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
96977E171CBD7F59000BEFC4 /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -33,6 +36,7 @@ ...@@ -33,6 +36,7 @@
960590261C388FD800691E88 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 960590261C388FD800691E88 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
960590291C388FD800691E88 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 960590291C388FD800691E88 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
9605902B1C388FD800691E88 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 9605902B1C388FD800691E88 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
96977E151CBD7F59000BEFC4 /* 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>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -40,6 +44,7 @@ ...@@ -40,6 +44,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
96977E161CBD7F59000BEFC4 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -49,6 +54,7 @@ ...@@ -49,6 +54,7 @@
960590131C388FD800691E88 = { 960590131C388FD800691E88 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96977E151CBD7F59000BEFC4 /* Material.framework */,
9605901E1C388FD800691E88 /* TextView */, 9605901E1C388FD800691E88 /* TextView */,
9605901D1C388FD800691E88 /* Products */, 9605901D1C388FD800691E88 /* Products */,
); );
......
...@@ -56,28 +56,13 @@ class ViewController: UIViewController, TextDelegate { ...@@ -56,28 +56,13 @@ class ViewController: UIViewController, TextDelegate {
/// Prepares the textView. /// Prepares the textView.
func prepareTextView() { func prepareTextView() {
let layoutManager: NSLayoutManager = NSLayoutManager() textView = TextView()
let textContainer: NSTextContainer = NSTextContainer(size: view.bounds.size) // textView.font = RobotoFont.regular
layoutManager.addTextContainer(textContainer) textView.backgroundColor = MaterialColor.grey.base
text.delegate = self
text.textStorage.addLayoutManager(layoutManager)
textView = TextView(textContainer: textContainer)
textView.font = RobotoFont.regular
textView.placeholderLabel = UILabel()
textView.placeholderLabel!.textColor = MaterialColor.grey.base
textView.placeholderLabel!.text = "Description"
textView.titleLabel = UILabel()
textView.titleLabel!.font = RobotoFont.mediumWithSize(12)
textView.titleLabelColor = MaterialColor.grey.base
textView.titleLabelActiveColor = MaterialColor.blue.accent3
view.addSubview(textView) view.addSubview(textView)
textView!.translatesAutoresizingMaskIntoConstraints = false textView!.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: textView!, top: 124, left: 24, bottom: 24, right: 24) MaterialLayout.alignToParent(view, child: textView!, top: 124, left: 24, bottom: 200, right: 24)
} }
/** /**
...@@ -97,4 +82,3 @@ class ViewController: UIViewController, TextDelegate { ...@@ -97,4 +82,3 @@ class ViewController: UIViewController, TextDelegate {
textStorage.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(16), range: result!.range) textStorage.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(16), range: result!.range)
} }
} }
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
9660162A1CB2F04E00AAB661 /* Material.h in Headers */ = {isa = PBXBuildFile; fileRef = 96D88C091C1328D800B91418 /* Material.h */; settings = {ATTRIBUTES = (Public, ); }; }; 9660162A1CB2F04E00AAB661 /* Material.h in Headers */ = {isa = PBXBuildFile; fileRef = 96D88C091C1328D800B91418 /* Material.h */; settings = {ATTRIBUTES = (Public, ); }; };
96815B381CA07BA20006CBE2 /* MaterialViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967887881C9777CB0037F6C9 /* MaterialViewTests.swift */; }; 96815B381CA07BA20006CBE2 /* MaterialViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967887881C9777CB0037F6C9 /* MaterialViewTests.swift */; };
96977DA61CBB2E49000BEFC4 /* Material+UIImage+FilterBlur.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96977DA51CBB2E49000BEFC4 /* Material+UIImage+FilterBlur.swift */; }; 96977DA61CBB2E49000BEFC4 /* Material+UIImage+FilterBlur.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96977DA51CBB2E49000BEFC4 /* Material+UIImage+FilterBlur.swift */; };
96977E191CBDA44B000BEFC4 /* MaterialTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96977E181CBDA44B000BEFC4 /* MaterialTextView.swift */; };
96BCB7A11CB40DC500C806FE /* BottomNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */; }; 96BCB7A11CB40DC500C806FE /* BottomNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */; };
96BCB7A21CB40DC500C806FE /* BottomTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7591CB40DC500C806FE /* BottomTabBar.swift */; }; 96BCB7A21CB40DC500C806FE /* BottomTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7591CB40DC500C806FE /* BottomTabBar.swift */; };
96BCB7A31CB40DC500C806FE /* CapturePreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB75A1CB40DC500C806FE /* CapturePreview.swift */; }; 96BCB7A31CB40DC500C806FE /* CapturePreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB75A1CB40DC500C806FE /* CapturePreview.swift */; };
...@@ -199,6 +200,7 @@ ...@@ -199,6 +200,7 @@
9660161C1CB2ED6C00AAB661 /* Material OSX Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Material OSX Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 9660161C1CB2ED6C00AAB661 /* Material OSX Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Material OSX Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
967887881C9777CB0037F6C9 /* MaterialViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialViewTests.swift; sourceTree = "<group>"; }; 967887881C9777CB0037F6C9 /* MaterialViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialViewTests.swift; sourceTree = "<group>"; };
96977DA51CBB2E49000BEFC4 /* Material+UIImage+FilterBlur.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIImage+FilterBlur.swift"; sourceTree = "<group>"; }; 96977DA51CBB2E49000BEFC4 /* Material+UIImage+FilterBlur.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIImage+FilterBlur.swift"; sourceTree = "<group>"; };
96977E181CBDA44B000BEFC4 /* MaterialTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTextView.swift; sourceTree = "<group>"; };
96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomNavigationController.swift; sourceTree = "<group>"; }; 96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomNavigationController.swift; sourceTree = "<group>"; };
96BCB7591CB40DC500C806FE /* BottomTabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomTabBar.swift; sourceTree = "<group>"; }; 96BCB7591CB40DC500C806FE /* BottomTabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomTabBar.swift; sourceTree = "<group>"; };
96BCB75A1CB40DC500C806FE /* CapturePreview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreview.swift; sourceTree = "<group>"; }; 96BCB75A1CB40DC500C806FE /* CapturePreview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreview.swift; sourceTree = "<group>"; };
...@@ -577,6 +579,7 @@ ...@@ -577,6 +579,7 @@
96BCB79C1CB40DC500C806FE /* TextField.swift */, 96BCB79C1CB40DC500C806FE /* TextField.swift */,
96BCB79D1CB40DC500C806FE /* TextStorage.swift */, 96BCB79D1CB40DC500C806FE /* TextStorage.swift */,
96BCB79E1CB40DC500C806FE /* TextView.swift */, 96BCB79E1CB40DC500C806FE /* TextView.swift */,
96977E181CBDA44B000BEFC4 /* MaterialTextView.swift */,
); );
name = Text; name = Text;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -863,6 +866,7 @@ ...@@ -863,6 +866,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
96977E191CBDA44B000BEFC4 /* MaterialTextView.swift in Sources */,
96BCB7C01CB40DC500C806FE /* MaterialDataSourceItem.swift in Sources */, 96BCB7C01CB40DC500C806FE /* MaterialDataSourceItem.swift in Sources */,
96BCB7AC1CB40DC500C806FE /* Material+Obj-C.swift in Sources */, 96BCB7AC1CB40DC500C806FE /* Material+Obj-C.swift in Sources */,
96BCB7BB1CB40DC500C806FE /* MaterialCollectionViewCell.swift in Sources */, 96BCB7BB1CB40DC500C806FE /* MaterialCollectionViewCell.swift in Sources */,
......
...@@ -92,7 +92,7 @@ public class BottomTabBar : UITabBar { ...@@ -92,7 +92,7 @@ public class BottomTabBar : UITabBar {
*/ */
@IBInspectable public var width: CGFloat { @IBInspectable public var width: CGFloat {
get { get {
return layer.frame.size.width return layer.frame.width
} }
set(value) { set(value) {
layer.frame.size.width = value layer.frame.size.width = value
...@@ -107,7 +107,7 @@ public class BottomTabBar : UITabBar { ...@@ -107,7 +107,7 @@ public class BottomTabBar : UITabBar {
*/ */
@IBInspectable public var height: CGFloat { @IBInspectable public var height: CGFloat {
get { get {
return layer.frame.size.height return layer.frame.height
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
......
...@@ -111,7 +111,7 @@ public class MaterialButton : UIButton { ...@@ -111,7 +111,7 @@ public class MaterialButton : UIButton {
*/ */
@IBInspectable public var width: CGFloat { @IBInspectable public var width: CGFloat {
get { get {
return layer.frame.size.width return layer.frame.width
} }
set(value) { set(value) {
layer.frame.size.width = value layer.frame.size.width = value
...@@ -129,7 +129,7 @@ public class MaterialButton : UIButton { ...@@ -129,7 +129,7 @@ public class MaterialButton : UIButton {
*/ */
@IBInspectable public var height: CGFloat { @IBInspectable public var height: CGFloat {
get { get {
return layer.frame.size.height return layer.frame.height
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
......
...@@ -218,7 +218,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -218,7 +218,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/ */
@IBInspectable public var width: CGFloat { @IBInspectable public var width: CGFloat {
get { get {
return layer.frame.size.width return layer.frame.width
} }
set(value) { set(value) {
layer.frame.size.width = value layer.frame.size.width = value
...@@ -236,7 +236,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -236,7 +236,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/ */
@IBInspectable public var height: CGFloat { @IBInspectable public var height: CGFloat {
get { get {
return layer.frame.size.height return layer.frame.height
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
......
...@@ -97,7 +97,7 @@ public class MaterialSwitch : UIControl { ...@@ -97,7 +97,7 @@ public class MaterialSwitch : UIControl {
/// A property that accesses the layer.frame.size.width property. /// A property that accesses the layer.frame.size.width property.
@IBInspectable public var width: CGFloat { @IBInspectable public var width: CGFloat {
get { get {
return layer.frame.size.width return layer.frame.width
} }
set(value) { set(value) {
layer.frame.size.width = value layer.frame.size.width = value
...@@ -107,7 +107,7 @@ public class MaterialSwitch : UIControl { ...@@ -107,7 +107,7 @@ public class MaterialSwitch : UIControl {
/// A property that accesses the layer.frame.size.height property. /// A property that accesses the layer.frame.size.height property.
@IBInspectable public var height: CGFloat { @IBInspectable public var height: CGFloat {
get { get {
return layer.frame.size.height return layer.frame.height
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
......
...@@ -110,7 +110,7 @@ public class MaterialTableViewCell : UITableViewCell { ...@@ -110,7 +110,7 @@ public class MaterialTableViewCell : UITableViewCell {
*/ */
@IBInspectable public var width: CGFloat { @IBInspectable public var width: CGFloat {
get { get {
return layer.frame.size.width return layer.frame.width
} }
set(value) { set(value) {
layer.frame.size.width = value layer.frame.size.width = value
...@@ -125,7 +125,7 @@ public class MaterialTableViewCell : UITableViewCell { ...@@ -125,7 +125,7 @@ public class MaterialTableViewCell : UITableViewCell {
*/ */
@IBInspectable public var height: CGFloat { @IBInspectable public var height: CGFloat {
get { get {
return layer.frame.size.height return layer.frame.height
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
@objc(MaterialTextViewDelegate)
public protocol MaterialTextViewDelegate : UITextViewDelegate {}
@IBDesignable
@objc(MaterialTextView)
public class MaterialTextView: UITextView {
/**
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame.
*/
@IBInspectable public var masksToBounds: Bool {
get {
return layer.masksToBounds
}
set(value) {
layer.masksToBounds = value
}
}
/// A property that accesses the backing layer's backgroundColor.
@IBInspectable public override var backgroundColor: UIColor? {
didSet {
layer.backgroundColor = backgroundColor?.CGColor
}
}
/// A property that accesses the layer.frame.origin.x property.
@IBInspectable public var x: CGFloat {
get {
return layer.frame.origin.x
}
set(value) {
layer.frame.origin.x = value
}
}
/// A property that accesses the layer.frame.origin.y property.
@IBInspectable public var y: CGFloat {
get {
return layer.frame.origin.y
}
set(value) {
layer.frame.origin.y = value
}
}
/// A property that accesses the layer.frame.size.width property.
@IBInspectable public var width: CGFloat {
get {
return layer.frame.width
}
set(value) {
layer.frame.size.width = value
}
}
/// A property that accesses the layer.frame.size.height property.
@IBInspectable public var height: CGFloat {
get {
return layer.frame.height
}
set(value) {
layer.frame.size.height = value
}
}
/// A property that accesses the backing layer's shadowColor.
@IBInspectable public var shadowColor: UIColor? {
didSet {
layer.shadowColor = shadowColor?.CGColor
}
}
/// A property that accesses the backing layer's shadowOffset.
@IBInspectable public var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
}
}
/// A property that accesses the backing layer's shadowOpacity.
@IBInspectable public var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
}
}
/// A property that accesses the backing layer's shadowRadius.
@IBInspectable public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
}
}
/// A property that accesses the backing layer's shadowPath.
@IBInspectable public var shadowPath: CGPath? {
get {
return layer.shadowPath
}
set(value) {
layer.shadowPath = value
}
}
/// Enables automatic shadowPath sizing.
@IBInspectable public var shadowPathAutoSizeEnabled: Bool = true {
didSet {
if shadowPathAutoSizeEnabled {
layoutShadowPath()
} else {
shadowPath = nil
}
}
}
/**
A property that sets the shadowOffset, shadowOpacity, and shadowRadius
for the backing layer. This is the preferred method of setting depth
in order to maintain consitency across UI objects.
*/
public var depth: MaterialDepth = .None {
didSet {
let value: MaterialDepthType = MaterialDepthToValue(depth)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
layoutShadowPath()
}
}
/// A property that sets the cornerRadius of the backing layer.
public var cornerRadiusPreset: MaterialRadius = .None {
didSet {
if let v: MaterialRadius = cornerRadiusPreset {
cornerRadius = MaterialRadiusToValue(v)
}
}
}
/// A property that accesses the layer.cornerRadius.
@IBInspectable public var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set(value) {
layer.cornerRadius = value
layoutShadowPath()
}
}
/// A preset property to set the borderWidth.
public var borderWidthPreset: MaterialBorder = .None {
didSet {
borderWidth = MaterialBorderToValue(borderWidthPreset)
}
}
/// A property that accesses the layer.borderWith.
@IBInspectable public var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set(value) {
layer.borderWidth = value
}
}
/// A property that accesses the layer.borderColor property.
@IBInspectable public var borderColor: UIColor? {
get {
return nil == layer.borderColor ? nil : UIColor(CGColor: layer.borderColor!)
}
set(value) {
layer.borderColor = value?.CGColor
}
}
/// A property that accesses the layer.position property.
@IBInspectable public var position: CGPoint {
get {
return layer.position
}
set(value) {
layer.position = value
}
}
/// A property that accesses the layer.zPosition property.
@IBInspectable public var zPosition: CGFloat {
get {
return layer.zPosition
}
set(value) {
layer.zPosition = value
}
}
/**
Text container UIEdgeInset preset property. This updates the
textContainerInset property with a preset value.
*/
public var textContainerInsetPreset: MaterialEdgeInset = .None {
didSet {
textContainerInset = MaterialEdgeInsetToValue(textContainerInsetPreset)
}
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
- Parameter textContainer: A NSTextContainer instance.
*/
public override init(frame: CGRect, textContainer: NSTextContainer?) {
let lm: NSLayoutManager = NSLayoutManager()
let tc: NSTextContainer = nil == textContainer ? NSTextContainer(size: CGSizeZero) : textContainer!
let ts: NSTextStorage = NSTextStorage()
lm.addTextContainer(tc)
ts.addLayoutManager(lm)
super.init(frame: frame, textContainer: tc)
prepareView()
}
/**
A convenience initializer that is mostly used with AutoLayout.
*/
public convenience init() {
self.init(frame: CGRectNull, textContainer: nil)
}
/**
A convenience initializer that is mostly used with AutoLayout.
- Parameter textContainer: A NSTextContainer instance.
*/
public convenience init(textContainer: NSTextContainer) {
self.init(frame: CGRectNull, textContainer: textContainer)
}
/**
A convenience initializer.
- Parameter frame: A CGRect defining the frame of the view.
*/
public convenience init(frame: CGRect) {
self.init(frame: frame, textContainer: nil)
}
/** Denitializer. This should never be called unless you know
what you are doing.
*/
deinit {
removeNotificationHandlers()
}
/// Overriding the layout callback for sublayers.
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
layoutShadowPath()
}
}
/**
A method that accepts CAAnimation objects and executes them on the
view's backing layer.
- Parameter animation: A CAAnimation instance.
*/
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)
}
}
/**
A delegation method that is executed when the backing layer starts
running an animation.
- Parameter anim: The currently running CAAnimation instance.
*/
public override func animationDidStart(anim: CAAnimation) {
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStart?(anim)
}
/**
A delegation method that is executed when the backing layer stops
running an animation.
- Parameter anim: The CAAnimation instance that stopped running.
- Parameter flag: A boolean that indicates if the animation stopped
because it was completed or interrupted. True if completed, false
if interrupted.
*/
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation {
if let v: AnyObject = b.toValue {
if let k: String = b.keyPath {
layer.setValue(v, forKeyPath: k)
layer.removeAnimationForKey(k)
}
}
}
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
}
/// Notification handler for when text editing began.
internal func handleTextViewTextDidBegin() {
}
/// Notification handler for when text changed.
internal func handleTextViewTextDidChange() {
}
/// Notification handler for when text editing ended.
internal func handleTextViewTextDidEnd() {
}
/// Sets the shadow path.
internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled {
if .None == depth {
shadowPath = nil
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
} else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
}
}
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
private func prepareView() {
textContainerInsetPreset = .Square3
backgroundColor = MaterialColor.white
textColor = MaterialColor.darkText.primary
removeNotificationHandlers()
prepareNotificationHandlers()
}
/// Prepares the Notification handlers.
private func prepareNotificationHandlers() {
let dc: NSNotificationCenter = NSNotificationCenter.defaultCenter()
dc.addObserver(self, selector: #selector(handleTextViewTextDidBegin), name: UITextViewTextDidBeginEditingNotification, object: nil)
dc.addObserver(self, selector: #selector(handleTextViewTextDidChange), name: UITextViewTextDidChangeNotification, object: nil)
dc.addObserver(self, selector: #selector(handleTextViewTextDidEnd), name: UITextViewTextDidEndEditingNotification, object: nil)
}
/// Removes the Notification handlers.
private func removeNotificationHandlers() {
let dc: NSNotificationCenter = NSNotificationCenter.defaultCenter()
dc.removeObserver(self, name: UITextViewTextDidBeginEditingNotification, object: nil)
dc.removeObserver(self, name: UITextViewTextDidChangeNotification, object: nil)
dc.removeObserver(self, name: UITextViewTextDidEndEditingNotification, object: nil)
}
}
...@@ -166,7 +166,7 @@ public class MaterialView : UIView { ...@@ -166,7 +166,7 @@ public class MaterialView : UIView {
*/ */
@IBInspectable public var width: CGFloat { @IBInspectable public var width: CGFloat {
get { get {
return layer.frame.size.width return layer.frame.width
} }
set(value) { set(value) {
layer.frame.size.width = value layer.frame.size.width = value
...@@ -184,7 +184,7 @@ public class MaterialView : UIView { ...@@ -184,7 +184,7 @@ public class MaterialView : UIView {
*/ */
@IBInspectable public var height: CGFloat { @IBInspectable public var height: CGFloat {
get { get {
return layer.frame.size.height return layer.frame.height
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
......
...@@ -134,7 +134,7 @@ public class NavigationBar : UINavigationBar { ...@@ -134,7 +134,7 @@ public class NavigationBar : UINavigationBar {
*/ */
@IBInspectable public var width: CGFloat { @IBInspectable public var width: CGFloat {
get { get {
return layer.frame.size.width return layer.frame.width
} }
set(value) { set(value) {
layer.frame.size.width = value layer.frame.size.width = value
...@@ -149,7 +149,7 @@ public class NavigationBar : UINavigationBar { ...@@ -149,7 +149,7 @@ public class NavigationBar : UINavigationBar {
*/ */
@IBInspectable public var height: CGFloat { @IBInspectable public var height: CGFloat {
get { get {
return layer.frame.size.height return layer.frame.height
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
......
...@@ -80,7 +80,7 @@ public class TextField : UITextField { ...@@ -80,7 +80,7 @@ public class TextField : UITextField {
/// A property that accesses the layer.frame.size.width property. /// A property that accesses the layer.frame.size.width property.
@IBInspectable public var width: CGFloat { @IBInspectable public var width: CGFloat {
get { get {
return layer.frame.size.width return layer.frame.width
} }
set(value) { set(value) {
layer.frame.size.width = value layer.frame.size.width = value
...@@ -90,7 +90,7 @@ public class TextField : UITextField { ...@@ -90,7 +90,7 @@ public class TextField : UITextField {
/// A property that accesses the layer.frame.size.height property. /// A property that accesses the layer.frame.size.height property.
@IBInspectable public var height: CGFloat { @IBInspectable public var height: CGFloat {
get { get {
return layer.frame.size.height return layer.frame.height
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
......
...@@ -35,269 +35,100 @@ public protocol TextViewDelegate : UITextViewDelegate {} ...@@ -35,269 +35,100 @@ public protocol TextViewDelegate : UITextViewDelegate {}
@IBDesignable @IBDesignable
@objc(TextView) @objc(TextView)
public class TextView: UITextView { public class TextView: MaterialView {
/// Reference to the textView.
public private(set) var textView: MaterialTextView!
/** /**
This property is the same as clipsToBounds. It crops any of the view's Text container UIEdgeInset preset property. This updates the
contents from bleeding past the view's frame. textContainerInset property with a preset value.
*/ */
@IBInspectable public var masksToBounds: Bool { public var textContainerInsetPreset: MaterialEdgeInset {
get { get {
return layer.masksToBounds return textView.textContainerInsetPreset
} }
set(value) { set(value) {
layer.masksToBounds = value textView.textContainerInsetPreset = value
}
}
/// A property that accesses the backing layer's backgroundColor.
@IBInspectable public override var backgroundColor: UIColor? {
didSet {
layer.backgroundColor = backgroundColor?.CGColor
} }
} }
/// A property that accesses the layer.frame.origin.x property. /// Text container UIEdgeInset property.
@IBInspectable public var x: CGFloat { public var textContainerInset: UIEdgeInsets {
get {
return layer.frame.origin.x
}
set(value) {
layer.frame.origin.x = value
}
}
/// A property that accesses the layer.frame.origin.y property.
@IBInspectable public var y: CGFloat {
get {
return layer.frame.origin.y
}
set(value) {
layer.frame.origin.y = value
}
}
/// A property that accesses the layer.frame.size.width property.
@IBInspectable public var width: CGFloat {
get {
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
}
}
/// A property that accesses the layer.frame.size.height property.
@IBInspectable public var height: CGFloat {
get {
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
}
}
/// A property that accesses the backing layer's shadowColor.
@IBInspectable public var shadowColor: UIColor? {
didSet {
layer.shadowColor = shadowColor?.CGColor
}
}
/// A property that accesses the backing layer's shadowOffset.
@IBInspectable public var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
}
}
/// A property that accesses the backing layer's shadowOpacity.
@IBInspectable public var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
}
}
/// A property that accesses the backing layer's shadowRadius.
@IBInspectable public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
}
}
/// A property that accesses the backing layer's shadowPath.
@IBInspectable public var shadowPath: CGPath? {
get { get {
return layer.shadowPath return textView.textContainerInset
} }
set(value) { set(value) {
layer.shadowPath = value textView.textContainerInset = value
}
}
/// Enables automatic shadowPath sizing.
@IBInspectable public var shadowPathAutoSizeEnabled: Bool = true {
didSet {
if shadowPathAutoSizeEnabled {
layoutShadowPath()
} else {
shadowPath = nil
}
} }
} }
/** /**
A property that sets the shadowOffset, shadowOpacity, and shadowRadius The title UILabel that is displayed when there is text. The
for the backing layer. This is the preferred method of setting depth titleLabel text value is updated with the placeholder text
in order to maintain consitency across UI objects. value before being displayed.
*/ */
public var depth: MaterialDepth = .None { @IBInspectable public private(set) var titleLabel: UILabel!
didSet {
let value: MaterialDepthType = MaterialDepthToValue(depth)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
layoutShadowPath()
}
}
/// A property that sets the cornerRadius of the backing layer. /// The color of the titleLabel text when the textField is not active.
public var cornerRadiusPreset: MaterialRadius = .None { @IBInspectable public var titleLabelColor: UIColor? {
didSet { didSet {
if let v: MaterialRadius = cornerRadiusPreset { titleLabel.textColor = titleLabelColor
cornerRadius = MaterialRadiusToValue(v) if nil == lineLayerColor {
} lineLayerColor = titleLabelColor
}
}
/// A property that accesses the layer.cornerRadius.
@IBInspectable public var cornerRadius: CGFloat {
get {
return layer.cornerRadius
} }
set(value) {
layer.cornerRadius = value
layoutShadowPath()
} }
} }
/// A preset property to set the borderWidth. /// The color of the titleLabel text when the textField is active.
public var borderWidthPreset: MaterialBorder = .None { @IBInspectable public var titleLabelActiveColor: UIColor? {
didSet { didSet {
borderWidth = MaterialBorderToValue(borderWidthPreset) if nil == lineLayerActiveColor {
} lineLayerActiveColor = titleLabelActiveColor
}
/// A property that accesses the layer.borderWith.
@IBInspectable public var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set(value) {
layer.borderWidth = value
}
}
/// A property that accesses the layer.borderColor property.
@IBInspectable public var borderColor: UIColor? {
get {
return nil == layer.borderColor ? nil : UIColor(CGColor: layer.borderColor!)
} }
set(value) { tintColor = titleLabelActiveColor
layer.borderColor = value?.CGColor
}
}
/// A property that accesses the layer.position property.
@IBInspectable public var position: CGPoint {
get {
return layer.position
}
set(value) {
layer.position = value
}
}
/// A property that accesses the layer.zPosition property.
@IBInspectable public var zPosition: CGFloat {
get {
return layer.zPosition
}
set(value) {
layer.zPosition = value
} }
} }
/** /**
The title UILabel that is displayed when there is text. The A property that sets the distance between the textField and
titleLabel text value is updated with the placeholderLabel titleLabel.
text value before being displayed.
*/ */
public var titleLabel: UILabel? { @IBInspectable public var titleLabelAnimationDistance: CGFloat = 4
didSet {
prepareTitleLabel()
}
}
/// The color of the titleLabel text when the textView is not active.
@IBInspectable public var titleLabelColor: UIColor? {
didSet {
titleLabel?.textColor = titleLabelColor
}
}
/// The color of the titleLabel text when the textView is active. /// The bottom border layer.
@IBInspectable public var titleLabelActiveColor: UIColor? public private(set) lazy var lineLayer: CAShapeLayer = CAShapeLayer()
/** /**
A property that sets the distance between the textView and A property that sets the distance between the textField and
titleLabel. lineLayer.
*/ */
@IBInspectable public var titleLabelAnimationDistance: CGFloat = 8 @IBInspectable public var lineLayerDistance: CGFloat = 4
/// Placeholder UILabel view. /// The lineLayer color when inactive.
public var placeholderLabel: UILabel? { @IBInspectable public var lineLayerColor: UIColor? {
didSet { didSet {
preparePlaceholderLabel() lineLayer.backgroundColor = lineLayerColor?.CGColor
} }
} }
/// An override to the text property. /// The lineLayer active color.
@IBInspectable public override var text: String! { @IBInspectable public var lineLayerActiveColor: UIColor?
didSet {
handleTextViewTextDidChange()
}
}
/// An override to the attributedText property. /// Sets the placeholder value.
public override var attributedText: NSAttributedString! { @IBInspectable public var placeholder: String? {
didSet { didSet {
handleTextViewTextDidChange() if let v: String = placeholder {
} // attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor])
} }
/**
Text container UIEdgeInset preset property. This updates the
textContainerInset property with a preset value.
*/
public var textContainerInsetPreset: MaterialEdgeInset = .None {
didSet {
textContainerInset = MaterialEdgeInsetToValue(textContainerInsetPreset)
} }
} }
/// Text container UIEdgeInset property. /// Placeholder textColor.
public override var textContainerInset: UIEdgeInsets { @IBInspectable public var placeholderTextColor: UIColor = MaterialColor.darkText.others {
didSet { didSet {
reloadView() if let v: String = placeholder {
// attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor])
}
} }
} }
...@@ -310,153 +141,15 @@ public class TextView: UITextView { ...@@ -310,153 +141,15 @@ public class TextView: UITextView {
prepareView() prepareView()
} }
/** public init() {
An initializer that initializes the object with a CGRect object. super.init(frame: CGRectNull)
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
- Parameter textContainer: A NSTextContainer instance.
*/
public override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
prepareView()
}
/**
A convenience initializer that is mostly used with AutoLayout.
- Parameter textContainer: A NSTextContainer instance.
*/
public convenience init(textContainer: NSTextContainer?) {
self.init(frame: CGRectNull, textContainer: textContainer)
}
/** Denitializer. This should never be called unless you know
what you are doing.
*/
deinit {
removeNotificationHandlers()
}
/// Overriding the layout callback for subviews.
public override func layoutSubviews() {
super.layoutSubviews()
placeholderLabel?.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2
titleLabel?.frame.size.width = bounds.width
} }
/// Overriding the layout callback for sublayers. /// Overriding the layout callback for sublayers.
public override func layoutSublayersOfLayer(layer: CALayer) { public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer) super.layoutSublayersOfLayer(layer)
if self.layer == layer { if self.layer == layer {
layoutShadowPath() layoutLineLayer()
}
}
/**
A method that accepts CAAnimation objects and executes them on the
view's backing layer.
- Parameter animation: A CAAnimation instance.
*/
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)
}
}
/**
A delegation method that is executed when the backing layer starts
running an animation.
- Parameter anim: The currently running CAAnimation instance.
*/
public override func animationDidStart(anim: CAAnimation) {
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStart?(anim)
}
/**
A delegation method that is executed when the backing layer stops
running an animation.
- Parameter anim: The CAAnimation instance that stopped running.
- Parameter flag: A boolean that indicates if the animation stopped
because it was completed or interrupted. True if completed, false
if interrupted.
*/
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation {
if let v: AnyObject = b.toValue {
if let k: String = b.keyPath {
layer.setValue(v, forKeyPath: k)
layer.removeAnimationForKey(k)
}
}
}
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
}
/// Reloads necessary components when the view has changed.
internal func reloadView() {
if let p = placeholderLabel {
removeConstraints(constraints)
MaterialLayout.alignToParent(self,
child: p,
top: textContainerInset.top,
left: textContainerInset.left + textContainer.lineFragmentPadding,
bottom: textContainerInset.bottom,
right: textContainerInset.right + textContainer.lineFragmentPadding)
}
}
/// Notification handler for when text editing began.
internal func handleTextViewTextDidBegin() {
titleLabel?.textColor = titleLabelActiveColor
}
/// Notification handler for when text changed.
internal func handleTextViewTextDidChange() {
if let p = placeholderLabel {
p.hidden = !(true == text?.isEmpty)
}
if 0 < text?.utf16.count {
showTitleLabel()
} else if 0 == text?.utf16.count {
hideTitleLabel()
}
}
/// Notification handler for when text editing ended.
internal func handleTextViewTextDidEnd() {
if 0 < text?.utf16.count {
showTitleLabel()
} else if 0 == text?.utf16.count {
hideTitleLabel()
}
titleLabel?.textColor = titleLabelColor
}
/// Sets the shadow path.
internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled {
if .None == depth {
shadowPath = nil
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
} else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
}
} }
} }
...@@ -467,85 +160,50 @@ public class TextView: UITextView { ...@@ -467,85 +160,50 @@ public class TextView: UITextView {
The super.prepareView method should always be called immediately The super.prepareView method should always be called immediately
when subclassing. when subclassing.
*/ */
private func prepareView() { public override func prepareView() {
textContainerInset = MaterialEdgeInsetToValue(.None) super.prepareView()
backgroundColor = MaterialColor.white backgroundColor = MaterialColor.white
masksToBounds = false masksToBounds = false
removeNotificationHandlers() prepareTextView()
prepareNotificationHandlers() prepareTitleLabel()
reloadView() prepareLineLayer()
} }
/// prepares the placeholderLabel property. /// Prepares the textView.
private func preparePlaceholderLabel() { private func prepareTextView() {
if let v: UILabel = placeholderLabel { textView = MaterialTextView()
v.translatesAutoresizingMaskIntoConstraints = false addSubview(textView)
v.font = font textView.translatesAutoresizingMaskIntoConstraints = false
v.textAlignment = textAlignment MaterialLayout.alignToParent(self, child: textView)
v.numberOfLines = 0
v.backgroundColor = MaterialColor.clear
addSubview(v)
reloadView()
handleTextViewTextDidChange()
}
} }
/// Prepares the titleLabel property. /// Prepares the titleLabel.
private func prepareTitleLabel() { private func prepareTitleLabel() {
if let v: UILabel = titleLabel { titleLabel = UILabel()
v.hidden = true titleLabel.hidden = true
addSubview(v) titleLabel.font = RobotoFont.mediumWithSize(12)
if 0 < text?.utf16.count { addSubview(titleLabel)
showTitleLabel()
} else {
v.alpha = 0
}
}
}
/// Shows and animates the titleLabel property. titleLabelColor = placeholderTextColor
private func showTitleLabel() { titleLabelActiveColor = MaterialColor.blue.accent3
if let v: UILabel = titleLabel {
if v.hidden {
if let s: String = placeholderLabel?.text {
v.text = s
}
let h: CGFloat = ceil(v.font.lineHeight)
v.frame = CGRectMake(0, -h, bounds.width, h)
v.hidden = false
UIView.animateWithDuration(0.25, animations: { [unowned self] in
v.alpha = 1
v.frame.origin.y = -v.frame.height - self.titleLabelAnimationDistance
})
}
}
}
/// Hides and animates the titleLabel property. // if 0 < text?.utf16.count {
private func hideTitleLabel() { //// showTitleLabel()
if let v: UILabel = titleLabel { // } else {
if !v.hidden { // titleLabel.alpha = 0
UIView.animateWithDuration(0.25, animations: { // }
v.alpha = 0
v.frame.origin.y = -v.frame.height
}) { _ in
v.hidden = true
}
}
}
} }
/// Prepares the Notification handlers. /// Prepares the lineLayer.
private func prepareNotificationHandlers() { private func prepareLineLayer() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidBegin), name: UITextViewTextDidBeginEditingNotification, object: nil) layoutLineLayer()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidChange), name: UITextViewTextDidChangeNotification, object: nil) layer.addSublayer(lineLayer)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidEnd), name: UITextViewTextDidEndEditingNotification, object: nil)
} }
/// Removes the Notification handlers. /// Layout the lineLayer.
private func removeNotificationHandlers() { private func layoutLineLayer() {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidBeginEditingNotification, object: nil) let h: CGFloat = 1 < lineLayer.frame.height ? lineLayer.frame.height : 1
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidChangeNotification, object: nil) lineLayer.frame = CGRectMake(0, bounds.height + lineLayerDistance, bounds.width, h)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidEndEditingNotification, object: nil) print(lineLayer.frame)
} }
} }
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