Commit e007f9b2 by Daniel Dahan

prepare for release

parent 60599d2b
......@@ -56,13 +56,28 @@ class ViewController: UIViewController, TextDelegate {
/// Prepares the textView.
func prepareTextView() {
textView = TextView()
// textView.font = RobotoFont.regular
textView.backgroundColor = MaterialColor.grey.base
let layoutManager: NSLayoutManager = NSLayoutManager()
let textContainer: NSTextContainer = NSTextContainer(size: view.bounds.size)
layoutManager.addTextContainer(textContainer)
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)
textView!.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: textView!, top: 124, left: 24, bottom: 200, right: 24)
MaterialLayout.alignToParent(view, child: textView!, top: 124, left: 24, bottom: 24, right: 24)
}
/**
......@@ -82,3 +97,4 @@ class ViewController: UIViewController, TextDelegate {
textStorage.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(16), range: result!.range)
}
}
Pod::Spec.new do |s|
s.name = 'Material'
s.version = '1.39.7'
s.version = '1.39.8'
s.license = 'BSD'
s.summary = 'Express your creativity with Material, an animation and graphics framework for Google\'s Material Design and Apple\'s Flat UI in Swift.'
s.homepage = 'http://cosmicmind.io'
......
......@@ -13,7 +13,6 @@
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 */; };
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 */; };
96BCB7A21CB40DC500C806FE /* BottomTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7591CB40DC500C806FE /* BottomTabBar.swift */; };
96BCB7A31CB40DC500C806FE /* CapturePreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB75A1CB40DC500C806FE /* CapturePreview.swift */; };
......@@ -200,7 +199,6 @@
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>"; };
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>"; };
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>"; };
......@@ -579,7 +577,6 @@
96BCB79C1CB40DC500C806FE /* TextField.swift */,
96BCB79D1CB40DC500C806FE /* TextStorage.swift */,
96BCB79E1CB40DC500C806FE /* TextView.swift */,
96977E181CBDA44B000BEFC4 /* MaterialTextView.swift */,
);
name = Text;
sourceTree = "<group>";
......@@ -866,7 +863,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
96977E191CBDA44B000BEFC4 /* MaterialTextView.swift in Sources */,
96BCB7C01CB40DC500C806FE /* MaterialDataSourceItem.swift in Sources */,
96BCB7AC1CB40DC500C806FE /* Material+Obj-C.swift in Sources */,
96BCB7BB1CB40DC500C806FE /* MaterialCollectionViewCell.swift in Sources */,
......
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.39.7</string>
<string>1.39.8</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -92,7 +92,7 @@ public class BottomTabBar : UITabBar {
*/
@IBInspectable public var width: CGFloat {
get {
return layer.frame.width
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
......@@ -107,7 +107,7 @@ public class BottomTabBar : UITabBar {
*/
@IBInspectable public var height: CGFloat {
get {
return layer.frame.height
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
......
......@@ -111,7 +111,7 @@ public class MaterialButton : UIButton {
*/
@IBInspectable public var width: CGFloat {
get {
return layer.frame.width
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
......@@ -129,7 +129,7 @@ public class MaterialButton : UIButton {
*/
@IBInspectable public var height: CGFloat {
get {
return layer.frame.height
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
......
......@@ -218,7 +218,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/
@IBInspectable public var width: CGFloat {
get {
return layer.frame.width
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
......@@ -236,7 +236,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/
@IBInspectable public var height: CGFloat {
get {
return layer.frame.height
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
......
......@@ -97,7 +97,7 @@ public class MaterialSwitch : UIControl {
/// A property that accesses the layer.frame.size.width property.
@IBInspectable public var width: CGFloat {
get {
return layer.frame.width
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
......@@ -107,7 +107,7 @@ public class MaterialSwitch : UIControl {
/// A property that accesses the layer.frame.size.height property.
@IBInspectable public var height: CGFloat {
get {
return layer.frame.height
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
......
......@@ -110,7 +110,7 @@ public class MaterialTableViewCell : UITableViewCell {
*/
@IBInspectable public var width: CGFloat {
get {
return layer.frame.width
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
......@@ -125,7 +125,7 @@ public class MaterialTableViewCell : UITableViewCell {
*/
@IBInspectable public var height: CGFloat {
get {
return layer.frame.height
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
......
......@@ -166,7 +166,7 @@ public class MaterialView : UIView {
*/
@IBInspectable public var width: CGFloat {
get {
return layer.frame.width
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
......@@ -184,7 +184,7 @@ public class MaterialView : UIView {
*/
@IBInspectable public var height: CGFloat {
get {
return layer.frame.height
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
......
......@@ -134,7 +134,7 @@ public class NavigationBar : UINavigationBar {
*/
@IBInspectable public var width: CGFloat {
get {
return layer.frame.width
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
......@@ -149,7 +149,7 @@ public class NavigationBar : UINavigationBar {
*/
@IBInspectable public var height: CGFloat {
get {
return layer.frame.height
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
......
......@@ -80,7 +80,7 @@ public class TextField : UITextField {
/// A property that accesses the layer.frame.size.width property.
@IBInspectable public var width: CGFloat {
get {
return layer.frame.width
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
......@@ -90,7 +90,7 @@ public class TextField : UITextField {
/// A property that accesses the layer.frame.size.height property.
@IBInspectable public var height: CGFloat {
get {
return layer.frame.height
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
......
......@@ -35,100 +35,269 @@ public protocol TextViewDelegate : UITextViewDelegate {}
@IBDesignable
@objc(TextView)
public class TextView: MaterialView {
/// Reference to the textView.
public private(set) var textView: MaterialTextView!
public class TextView: UITextView {
/**
Text container UIEdgeInset preset property. This updates the
textContainerInset property with a preset value.
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame.
*/
public var textContainerInsetPreset: MaterialEdgeInset {
@IBInspectable public var masksToBounds: Bool {
get {
return textView.textContainerInsetPreset
return layer.masksToBounds
}
set(value) {
textView.textContainerInsetPreset = value
layer.masksToBounds = value
}
}
/// Text container UIEdgeInset property.
public var textContainerInset: UIEdgeInsets {
/// 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.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 textView.textContainerInset
return layer.shadowRadius
}
set(value) {
textView.textContainerInset = 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
}
}
}
/**
The title UILabel that is displayed when there is text. The
titleLabel text value is updated with the placeholder text
value before being displayed.
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.
*/
@IBInspectable public private(set) var titleLabel: UILabel!
public var depth: MaterialDepth = .None {
didSet {
let value: MaterialDepthType = MaterialDepthToValue(depth)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
layoutShadowPath()
}
}
/// The color of the titleLabel text when the textField is not active.
@IBInspectable public var titleLabelColor: UIColor? {
/// A property that sets the cornerRadius of the backing layer.
public var cornerRadiusPreset: MaterialRadius = .None {
didSet {
titleLabel.textColor = titleLabelColor
if nil == lineLayerColor {
lineLayerColor = titleLabelColor
if let v: MaterialRadius = cornerRadiusPreset {
cornerRadius = MaterialRadiusToValue(v)
}
}
}
/// The color of the titleLabel text when the textField is active.
@IBInspectable public var titleLabelActiveColor: UIColor? {
/// 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 {
if nil == lineLayerActiveColor {
lineLayerActiveColor = titleLabelActiveColor
}
tintColor = titleLabelActiveColor
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
}
}
/**
A property that sets the distance between the textField and
titleLabel.
The title UILabel that is displayed when there is text. The
titleLabel text value is updated with the placeholderLabel
text value before being displayed.
*/
@IBInspectable public var titleLabelAnimationDistance: CGFloat = 4
public var titleLabel: UILabel? {
didSet {
prepareTitleLabel()
}
}
/// The color of the titleLabel text when the textView is not active.
@IBInspectable public var titleLabelColor: UIColor? {
didSet {
titleLabel?.textColor = titleLabelColor
}
}
/// The bottom border layer.
public private(set) lazy var lineLayer: CAShapeLayer = CAShapeLayer()
/// The color of the titleLabel text when the textView is active.
@IBInspectable public var titleLabelActiveColor: UIColor?
/**
A property that sets the distance between the textField and
lineLayer.
A property that sets the distance between the textView and
titleLabel.
*/
@IBInspectable public var lineLayerDistance: CGFloat = 4
@IBInspectable public var titleLabelAnimationDistance: CGFloat = 8
/// The lineLayer color when inactive.
@IBInspectable public var lineLayerColor: UIColor? {
/// Placeholder UILabel view.
public var placeholderLabel: UILabel? {
didSet {
lineLayer.backgroundColor = lineLayerColor?.CGColor
preparePlaceholderLabel()
}
}
/// The lineLayer active color.
@IBInspectable public var lineLayerActiveColor: UIColor?
/// An override to the text property.
@IBInspectable public override var text: String! {
didSet {
handleTextViewTextDidChange()
}
}
/// Sets the placeholder value.
@IBInspectable public var placeholder: String? {
/// An override to the attributedText property.
public override var attributedText: NSAttributedString! {
didSet {
if let v: String = placeholder {
// attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor])
}
handleTextViewTextDidChange()
}
}
/**
Text container UIEdgeInset preset property. This updates the
textContainerInset property with a preset value.
*/
public var textContainerInsetPreset: MaterialEdgeInset = .None {
didSet {
textContainerInset = MaterialEdgeInsetToValue(textContainerInsetPreset)
}
}
/// Placeholder textColor.
@IBInspectable public var placeholderTextColor: UIColor = MaterialColor.darkText.others {
/// Text container UIEdgeInset property.
public override var textContainerInset: UIEdgeInsets {
didSet {
if let v: String = placeholder {
// attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor])
}
reloadView()
}
}
......@@ -141,14 +310,152 @@ public class TextView: MaterialView {
prepareView()
}
public init() {
super.init(frame: CGRectNull)
/**
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?) {
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
}
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
layoutLineLayer()
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)
}
}
}
/// 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))
}
}
}
......@@ -159,50 +466,85 @@ public class TextView: MaterialView {
The super.prepareView method should always be called immediately
when subclassing.
*/
public override func prepareView() {
super.prepareView()
private func prepareView() {
textContainerInset = MaterialEdgeInsetToValue(.None)
backgroundColor = MaterialColor.white
masksToBounds = false
prepareTextView()
prepareTitleLabel()
prepareLineLayer()
removeNotificationHandlers()
prepareNotificationHandlers()
reloadView()
}
/// Prepares the textView.
private func prepareTextView() {
textView = MaterialTextView()
addSubview(textView)
textView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(self, child: textView)
/// prepares the placeholderLabel property.
private func preparePlaceholderLabel() {
if let v: UILabel = placeholderLabel {
v.translatesAutoresizingMaskIntoConstraints = false
v.font = font
v.textAlignment = textAlignment
v.numberOfLines = 0
v.backgroundColor = MaterialColor.clear
addSubview(v)
reloadView()
handleTextViewTextDidChange()
}
}
/// Prepares the titleLabel.
/// Prepares the titleLabel property.
private func prepareTitleLabel() {
titleLabel = UILabel()
titleLabel.hidden = true
titleLabel.font = RobotoFont.mediumWithSize(12)
addSubview(titleLabel)
titleLabelColor = placeholderTextColor
titleLabelActiveColor = MaterialColor.blue.accent3
// if 0 < text?.utf16.count {
//// showTitleLabel()
// } else {
// titleLabel.alpha = 0
// }
if let v: UILabel = titleLabel {
v.hidden = true
addSubview(v)
if 0 < text?.utf16.count {
showTitleLabel()
} else {
v.alpha = 0
}
}
}
/// Shows and animates the titleLabel property.
private func showTitleLabel() {
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.
private func hideTitleLabel() {
if let v: UILabel = titleLabel {
if !v.hidden {
UIView.animateWithDuration(0.25, animations: {
v.alpha = 0
v.frame.origin.y = -v.frame.height
}) { _ in
v.hidden = true
}
}
}
}
/// Prepares the lineLayer.
private func prepareLineLayer() {
layoutLineLayer()
layer.addSublayer(lineLayer)
/// Prepares the Notification handlers.
private func prepareNotificationHandlers() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidBegin), name: UITextViewTextDidBeginEditingNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidChange), name: UITextViewTextDidChangeNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidEnd), name: UITextViewTextDidEndEditingNotification, object: nil)
}
/// Layout the lineLayer.
private func layoutLineLayer() {
let h: CGFloat = 1 < lineLayer.frame.height ? lineLayer.frame.height : 1
lineLayer.frame = CGRectMake(0, bounds.height + lineLayerDistance, bounds.width, h)
print(lineLayer.frame)
/// Removes the Notification handlers.
private func removeNotificationHandlers() {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidBeginEditingNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidChangeNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidEndEditingNotification, object: nil)
}
}
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