Commit e007f9b2 by Daniel Dahan

prepare for release

parent 60599d2b
...@@ -56,13 +56,28 @@ class ViewController: UIViewController, TextDelegate { ...@@ -56,13 +56,28 @@ class ViewController: UIViewController, TextDelegate {
/// Prepares the textView. /// Prepares the textView.
func prepareTextView() { func prepareTextView() {
textView = TextView() let layoutManager: NSLayoutManager = NSLayoutManager()
// textView.font = RobotoFont.regular let textContainer: NSTextContainer = NSTextContainer(size: view.bounds.size)
textView.backgroundColor = MaterialColor.grey.base 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) view.addSubview(textView)
textView!.translatesAutoresizingMaskIntoConstraints = false 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 { ...@@ -82,3 +97,4 @@ class ViewController: UIViewController, TextDelegate {
textStorage.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(16), range: result!.range) textStorage.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(16), range: result!.range)
} }
} }
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Material' s.name = 'Material'
s.version = '1.39.7' s.version = '1.39.8'
s.license = 'BSD' 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.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' s.homepage = 'http://cosmicmind.io'
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
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 */; };
...@@ -200,7 +199,6 @@ ...@@ -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; }; 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>"; };
...@@ -579,7 +577,6 @@ ...@@ -579,7 +577,6 @@
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>";
...@@ -866,7 +863,6 @@ ...@@ -866,7 +863,6 @@
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 */,
......
...@@ -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.39.7</string> <string>1.39.8</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -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.width return layer.frame.size.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.height return layer.frame.size.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.width return layer.frame.size.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.height return layer.frame.size.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.width return layer.frame.size.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.height return layer.frame.size.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.width return layer.frame.size.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.height return layer.frame.size.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.width return layer.frame.size.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.height return layer.frame.size.height
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
......
...@@ -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.width return layer.frame.size.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.height return layer.frame.size.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.width return layer.frame.size.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.height return layer.frame.size.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.width return layer.frame.size.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.height return layer.frame.size.height
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
......
...@@ -35,100 +35,269 @@ public protocol TextViewDelegate : UITextViewDelegate {} ...@@ -35,100 +35,269 @@ public protocol TextViewDelegate : UITextViewDelegate {}
@IBDesignable @IBDesignable
@objc(TextView) @objc(TextView)
public class TextView: MaterialView { public class TextView: UITextView {
/// Reference to the textView.
public private(set) var textView: MaterialTextView!
/** /**
Text container UIEdgeInset preset property. This updates the This property is the same as clipsToBounds. It crops any of the view's
textContainerInset property with a preset value. contents from bleeding past the view's frame.
*/ */
public var textContainerInsetPreset: MaterialEdgeInset { @IBInspectable public var masksToBounds: Bool {
get { get {
return textView.textContainerInsetPreset return layer.masksToBounds
} }
set(value) { set(value) {
textView.textContainerInsetPreset = value layer.masksToBounds = value
} }
} }
/// Text container UIEdgeInset property. /// A property that accesses the backing layer's backgroundColor.
public var textContainerInset: UIEdgeInsets { @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 { get {
return textView.textContainerInset return layer.shadowRadius
} }
set(value) { 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 A property that sets the shadowOffset, shadowOpacity, and shadowRadius
titleLabel text value is updated with the placeholder text for the backing layer. This is the preferred method of setting depth
value before being displayed. 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. /// A property that sets the cornerRadius of the backing layer.
@IBInspectable public var titleLabelColor: UIColor? { public var cornerRadiusPreset: MaterialRadius = .None {
didSet { didSet {
titleLabel.textColor = titleLabelColor if let v: MaterialRadius = cornerRadiusPreset {
if nil == lineLayerColor { cornerRadius = MaterialRadiusToValue(v)
lineLayerColor = titleLabelColor
} }
} }
} }
/// The color of the titleLabel text when the textField is active. /// A property that accesses the layer.cornerRadius.
@IBInspectable public var titleLabelActiveColor: UIColor? { @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 { didSet {
if nil == lineLayerActiveColor { borderWidth = MaterialBorderToValue(borderWidthPreset)
lineLayerActiveColor = titleLabelActiveColor }
} }
tintColor = 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) {
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 The title UILabel that is displayed when there is text. The
titleLabel. 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. /// The color of the titleLabel text when the textView is active.
public private(set) lazy var lineLayer: CAShapeLayer = CAShapeLayer() @IBInspectable public var titleLabelActiveColor: UIColor?
/** /**
A property that sets the distance between the textField and A property that sets the distance between the textView and
lineLayer. titleLabel.
*/ */
@IBInspectable public var lineLayerDistance: CGFloat = 4 @IBInspectable public var titleLabelAnimationDistance: CGFloat = 8
/// The lineLayer color when inactive. /// Placeholder UILabel view.
@IBInspectable public var lineLayerColor: UIColor? { public var placeholderLabel: UILabel? {
didSet { didSet {
lineLayer.backgroundColor = lineLayerColor?.CGColor preparePlaceholderLabel()
} }
} }
/// The lineLayer active color. /// An override to the text property.
@IBInspectable public var lineLayerActiveColor: UIColor? @IBInspectable public override var text: String! {
didSet {
handleTextViewTextDidChange()
}
}
/// Sets the placeholder value. /// An override to the attributedText property.
@IBInspectable public var placeholder: String? { public override var attributedText: NSAttributedString! {
didSet { didSet {
if let v: String = placeholder { handleTextViewTextDidChange()
// 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)
} }
} }
/// Placeholder textColor. /// Text container UIEdgeInset property.
@IBInspectable public var placeholderTextColor: UIColor = MaterialColor.darkText.others { public override var textContainerInset: UIEdgeInsets {
didSet { didSet {
if let v: String = placeholder { reloadView()
// attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor])
}
} }
} }
...@@ -141,14 +310,152 @@ public class TextView: MaterialView { ...@@ -141,14 +310,152 @@ public class TextView: MaterialView {
prepareView() 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) { public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer) super.layoutSublayersOfLayer(layer)
if self.layer == 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 { ...@@ -159,50 +466,85 @@ public class TextView: MaterialView {
The super.prepareView method should always be called immediately The super.prepareView method should always be called immediately
when subclassing. when subclassing.
*/ */
public override func prepareView() { private func prepareView() {
super.prepareView() textContainerInset = MaterialEdgeInsetToValue(.None)
backgroundColor = MaterialColor.white backgroundColor = MaterialColor.white
masksToBounds = false masksToBounds = false
prepareTextView() removeNotificationHandlers()
prepareTitleLabel() prepareNotificationHandlers()
prepareLineLayer() reloadView()
} }
/// Prepares the textView. /// prepares the placeholderLabel property.
private func prepareTextView() { private func preparePlaceholderLabel() {
textView = MaterialTextView() if let v: UILabel = placeholderLabel {
addSubview(textView) v.translatesAutoresizingMaskIntoConstraints = false
textView.translatesAutoresizingMaskIntoConstraints = false v.font = font
MaterialLayout.alignToParent(self, child: textView) v.textAlignment = textAlignment
v.numberOfLines = 0
v.backgroundColor = MaterialColor.clear
addSubview(v)
reloadView()
handleTextViewTextDidChange()
}
} }
/// Prepares the titleLabel. /// Prepares the titleLabel property.
private func prepareTitleLabel() { private func prepareTitleLabel() {
titleLabel = UILabel() if let v: UILabel = titleLabel {
titleLabel.hidden = true v.hidden = true
titleLabel.font = RobotoFont.mediumWithSize(12) addSubview(v)
addSubview(titleLabel) if 0 < text?.utf16.count {
showTitleLabel()
titleLabelColor = placeholderTextColor } else {
titleLabelActiveColor = MaterialColor.blue.accent3 v.alpha = 0
}
// if 0 < text?.utf16.count { }
//// showTitleLabel() }
// } else {
// titleLabel.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. /// Prepares the Notification handlers.
private func prepareLineLayer() { private func prepareNotificationHandlers() {
layoutLineLayer() NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidBegin), name: UITextViewTextDidBeginEditingNotification, object: nil)
layer.addSublayer(lineLayer) 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. /// Removes the Notification handlers.
private func layoutLineLayer() { private func removeNotificationHandlers() {
let h: CGFloat = 1 < lineLayer.frame.height ? lineLayer.frame.height : 1 NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidBeginEditingNotification, object: nil)
lineLayer.frame = CGRectMake(0, bounds.height + lineLayerDistance, bounds.width, h) NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidChangeNotification, object: nil)
print(lineLayer.frame) 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