Commit b66f37d2 by Daniel Dahan

updated internal presets and default values

parent 0209d364
......@@ -141,9 +141,9 @@ class ViewController: UIViewController {
*/
private func prepareCardViewWithAlteredAlignmentExample() {
let cardView: CardView = CardView()
cardView.dividerInsetsRef.left = 100
cardView.titleLabelInsetsRef.left = 100
cardView.detailLabelInsetsRef.left = 100
cardView.dividerInset.left = 100
cardView.titleLabelInset.left = 100
cardView.detailLabelInset.left = 100
cardView.pulseColor = MaterialColor.teal.lighten4
// Image.
......
......@@ -69,7 +69,7 @@ class ViewController: UIViewController {
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.mediumWithSize(24)
imageCardView.titleLabel = titleLabel
imageCardView.titleLabelInsetsRef.top = 100
imageCardView.titleLabelInset.top = 100
// Detail label.
let detailLabel: UILabel = UILabel()
......@@ -120,7 +120,7 @@ class ViewController: UIViewController {
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(24)
imageCardView.titleLabel = titleLabel
imageCardView.titleLabelInsetsRef.top = 80
imageCardView.titleLabelInset.top = 80
// Star button.
let img1: UIImage? = UIImage(named: "ic_star_grey_darken_2")
......
......@@ -253,7 +253,7 @@ class ViewController: UIViewController {
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(20)
navigationBarView.titleLabel = titleLabel
navigationBarView.titleLabelInsetsRef.left = 64
navigationBarView.titleLabelInset.left = 64
// Detail label.
let detailLabel: UILabel = UILabel()
......@@ -262,7 +262,7 @@ class ViewController: UIViewController {
detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regularWithSize(12)
navigationBarView.detailLabel = detailLabel
navigationBarView.detailLabelInsetsRef.left = 64
navigationBarView.detailLabelInset.left = 64
// Menu button.
let img1: UIImage? = UIImage(named: "ic_menu_white")
......
......@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
960590361C38B80400691E88 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 960590351C38B80400691E88 /* MaterialKit.framework */; };
960590371C38B80400691E88 /* MaterialKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 960590351C38B80400691E88 /* MaterialKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
966F57A11C226BAA009185B7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57A01C226BAA009185B7 /* AppDelegate.swift */; };
966F57A31C226BAA009185B7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57A21C226BAA009185B7 /* ViewController.swift */; };
966F57A81C226BAA009185B7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 966F57A71C226BAA009185B7 /* Assets.xcassets */; };
......@@ -20,6 +22,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
960590371C38B80400691E88 /* MaterialKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -27,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
960590351C38B80400691E88 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MaterialKit.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-gdulktuccbcfwbdfadtpxkworhyc/Build/Products/Debug-iphoneos/MaterialKit.framework"; sourceTree = "<absolute>"; };
966F579D1C226BAA009185B7 /* TextField.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TextField.app; sourceTree = BUILT_PRODUCTS_DIR; };
966F57A01C226BAA009185B7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
966F57A21C226BAA009185B7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
......@@ -40,6 +44,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
960590361C38B80400691E88 /* MaterialKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -49,6 +54,7 @@
966F57941C226BAA009185B7 = {
isa = PBXGroup;
children = (
960590351C38B80400691E88 /* MaterialKit.framework */,
966F579F1C226BAA009185B7 /* TextField */,
966F579E1C226BAA009185B7 /* Products */,
);
......
......@@ -50,8 +50,8 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField.textColor = MaterialColor.black
nameField.titleLabel = UILabel()
nameField.titleLabel!.font = RobotoFont.mediumWithSize(12)
nameField.titleLabelNormalColor = MaterialColor.grey.lighten2
nameField.titleLabelHighlightedColor = MaterialColor.blue.accent3
nameField.titleLabelTextColor = MaterialColor.grey.lighten2
nameField.titleLabelActiveTextColor = MaterialColor.blue.accent3
nameField.clearButtonMode = .WhileEditing
view.addSubview(nameField)
}
......@@ -68,13 +68,13 @@ class ViewController: UIViewController, TextFieldDelegate {
emailField.textColor = MaterialColor.black
emailField.titleLabel = UILabel()
emailField.titleLabel!.font = RobotoFont.mediumWithSize(12)
emailField.titleLabelNormalColor = MaterialColor.grey.lighten2
emailField.titleLabelHighlightedColor = MaterialColor.blue.accent3
emailField.titleLabelTextColor = MaterialColor.grey.lighten2
emailField.titleLabelActiveTextColor = MaterialColor.blue.accent3
emailField.clearButtonMode = .WhileEditing
emailField.detailLabel = UILabel()
emailField.detailLabel!.text = "Email is incorrect."
emailField.detailLabel!.font = RobotoFont.mediumWithSize(12)
emailField.detailLabelHighlightedColor = MaterialColor.red.accent3
emailField.detailLabelActiveTextColor = MaterialColor.red.accent3
view.addSubview(emailField)
}
......
......@@ -53,8 +53,8 @@ class ViewController: UIViewController, TextDelegate, TextViewDelegate {
textView.titleLabel = UILabel()
textView.titleLabel!.font = RobotoFont.mediumWithSize(12)
textView.titleLabelNormalColor = MaterialColor.grey.lighten2
textView.titleLabelHighlightedColor = MaterialColor.blue.accent3
textView.titleLabelTextColor = MaterialColor.grey.lighten2
textView.titleLabelActiveTextColor = MaterialColor.blue.accent3
view.addSubview(textView)
textView!.translatesAutoresizingMaskIntoConstraints = false
......@@ -69,6 +69,5 @@ class ViewController: UIViewController, TextDelegate, TextViewDelegate {
func textDidProcessEdit(text: Text, textStorage: TextStorage, string: String, result: NSTextCheckingResult?, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) {
textStorage.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(16), range: result!.range)
}
}
......@@ -83,9 +83,9 @@ class ViewController: UIViewController {
:description: General usage example.
*/
func prepareCardViewExampleTwo() {
secondCardView.dividerInsetsRef.left = 100
secondCardView.titleLabelInsetsRef.left = 100
secondCardView.detailLabelInsetsRef.left = 100
secondCardView.dividerInset.left = 100
secondCardView.titleLabelInset.left = 100
secondCardView.detailLabelInset.left = 100
secondCardView.pulseColor = MaterialColor.teal.lighten4
// Image.
......
......@@ -46,7 +46,7 @@ class ViewController: UIViewController {
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(24)
imageCardView.titleLabel = titleLabel
imageCardView.titleLabelInsetsRef.top = 80
imageCardView.titleLabelInset.top = 80
// Star button.
let img1: UIImage? = UIImage(named: "ic_star_grey_darken_2")
......@@ -77,7 +77,7 @@ class ViewController: UIViewController {
// Add buttons to right side.
imageCardView.rightButtons = [btn1, btn2, btn3]
imageCardView.rightButtonsInsetsRef.top = imageCardView.contentInsetsRef.top
imageCardView.rightButtonsInset.top = imageCardView.contentInset.top
}
}
......@@ -58,7 +58,7 @@ class ViewController: UIViewController {
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(20)
navigationBarView.titleLabel = titleLabel
navigationBarView.titleLabelInsetsRef.left = 64
navigationBarView.titleLabelInset.left = 64
// Detail label.
let detailLabel: UILabel = UILabel()
......@@ -67,7 +67,7 @@ class ViewController: UIViewController {
detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regularWithSize(12)
navigationBarView.detailLabel = detailLabel
navigationBarView.detailLabelInsetsRef.left = 64
navigationBarView.detailLabelInset.left = 64
// Menu button.
let img1: UIImage? = UIImage(named: "ic_menu_white")
......
......@@ -28,6 +28,7 @@ Run carthage to build the framework and drag the built MaterialKit.framework int
### Table of Contents
* [MaterialColor](#materialcolor)
* [MaterialLayer](#materiallayer)
* [MaterialView](#materialview)
* [MaterialPulseView](#materialpulseview)
......@@ -43,7 +44,6 @@ Run carthage to build the framework and drag the built MaterialKit.framework int
* [Crop Image](#cropimage)
* [Save Image To PhotoLibrary](#saveimagetophotolibrary)
* [Asynchronous Image Loading](#asynchronousimageloading)
* [MaterialColor](#materialcolor)
* [TextField](#textfield)
* [TextView](#textview)
* [Lines of Text](#linesoftext)
......@@ -63,6 +63,40 @@ Run carthage to build the framework and drag the built MaterialKit.framework int
* TimePicker
* More Examples
<a name="materialcolor"/>
### MaterialColor
Explore a complete range of Material Design colors using MaterialColor. Below is an example of setting a button's background color property.
![MaterialKitMaterialColorPalette](http://www.materialkit.io/MK/MaterialKitMaterialColorPalette.png)
```swift
let button: FabButton = FabButton()
button.backgroundColor = MaterialColor.blue.darken1
```
<a name="textfield"/>
### TextField
A TextField is an excellent way to improve UX. Checkout the Examples directory for a project using this component.
![MaterialKitTextField](http://www.materialkit.io/MK/MaterialKitTextField.gif)
```swift
let nameField: TextField = TextField(frame: CGRectMake(57, 100, 300, 24))
nameField.placeholder = "First Name"
nameField.font = RobotoFont.regularWithSize(20)
nameField.textColor = MaterialColor.black
nameField.titleLabel = UILabel()
nameField.titleLabel!.font = RobotoFont.mediumWithSize(12)
nameField.titleLabelNormalColor = MaterialColor.grey.lighten2
nameField.titleLabelHighlightedColor = MaterialColor.blue.accent3
nameField.clearButtonMode = .WhileEditing
// Add nameField to UIViewController.
view.addSubview(nameField)
```
<a name="materiallayer"/>
### MaterialLayer
......@@ -266,9 +300,9 @@ Adjust the alignment of the UI elements to create different configurations of th
```swift
let cardView: CardView = CardView()
cardView.dividerInsetsRef.left = 100
cardView.titleLabelInsetsRef.left = 100
cardView.detailLabelInsetsRef.left = 100
cardView.dividerInset.left = 100
cardView.titleLabelInset.left = 100
cardView.detailLabelInset.left = 100
cardView.pulseColor = MaterialColor.teal.lighten4
// Image.
......@@ -376,7 +410,7 @@ titleLabel.text = "Welcome Back!"
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.mediumWithSize(24)
imageCardView.titleLabel = titleLabel
imageCardView.titleLabelInsetsRef.top = 100
imageCardView.titleLabelInset.top = 100
// Detail label.
let detailLabel: UILabel = UILabel()
......@@ -427,7 +461,7 @@ titleLabel.text = "Material Design"
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(24)
imageCardView.titleLabel = titleLabel
imageCardView.titleLabelInsetsRef.top = 80
imageCardView.titleLabelInset.top = 80
// Star button.
let img1: UIImage? = UIImage(named: "ic_star_grey_darken_2")
......@@ -490,7 +524,7 @@ titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(20)
navigationBarView.titleLabel = titleLabel
navigationBarView.titleLabelInsetsRef.left = 64
navigationBarView.titleLabelInset.left = 64
// Detail label.
let detailLabel: UILabel = UILabel()
......@@ -499,7 +533,7 @@ detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regularWithSize(12)
navigationBarView.detailLabel = detailLabel
navigationBarView.detailLabelInsetsRef.left = 64
navigationBarView.detailLabelInset.left = 64
// Menu button.
let img1: UIImage? = UIImage(named: "ic_menu_white")
......@@ -620,40 +654,6 @@ UIImage.contentsOfURL(url) { (image: UIImage?, error: NSError?) in
}
```
<a name="materialcolor"/>
### MaterialColor
Explore a complete range of Material Design colors using MaterialColor. Below is an example of setting a button's background color property.
![MaterialKitMaterialColorPalette](http://www.materialkit.io/MK/MaterialKitMaterialColorPalette.png)
```swift
let button: FabButton = FabButton()
button.backgroundColor = MaterialColor.blue.darken1
```
<a name="textfield"/>
### TextField
A TextField is an excellent way to improve UX. Checkout the Examples directory for a project using this component.
![MaterialKitTextField](http://www.materialkit.io/MK/MaterialKitTextField.gif)
```swift
let nameField: TextField = TextField(frame: CGRectMake(57, 100, 300, 24))
nameField.placeholder = "First Name"
nameField.font = RobotoFont.regularWithSize(20)
nameField.textColor = MaterialColor.black
nameField.titleLabel = UILabel()
nameField.titleLabel!.font = RobotoFont.mediumWithSize(12)
nameField.titleLabelNormalColor = MaterialColor.grey.lighten2
nameField.titleLabelHighlightedColor = MaterialColor.blue.accent3
nameField.clearButtonMode = .WhileEditing
// Add nameField to UIViewController.
view.addSubview(nameField)
```
<a name="textview"/>
### TextView
......@@ -664,7 +664,7 @@ Easily match any regular expression pattern in a body of text. Below is an examp
```swift
class ViewController: UIViewController, TextDelegate, TextViewDelegate {
lazy var text: Text = Text()
var textView: TextView?
var textView: TextView!
override func viewDidLoad() {
super.viewDidLoad()
......@@ -685,18 +685,23 @@ class ViewController: UIViewController, TextDelegate, TextViewDelegate {
text.textStorage.addLayoutManager(layoutManager)
textView = TextView(frame: CGRectNull, textContainer: textContainer)
textView?.delegate = self
textView!.editable = true
textView!.selectable = true
textView!.font = RobotoFont.regular
textView.delegate = self
textView.editable = true
textView.selectable = true
textView.font = RobotoFont.regular
textView.placeholderLabel = UILabel()
textView.placeholderLabel!.textColor = MaterialColor.grey.base
textView.placeholderLabel!.text = "Description"
textView!.placeholderLabel = UILabel()
textView!.placeholderLabel!.textColor = MaterialColor.grey.base
textView!.placeholderLabel!.text = "MaterialKit TextView"
textView.titleLabel = UILabel()
textView.titleLabel!.font = RobotoFont.mediumWithSize(12)
textView.titleLabelNormalColor = MaterialColor.grey.lighten2
textView.titleLabelHighlightedColor = MaterialColor.blue.accent3
view.addSubview(textView!)
view.addSubview(textView)
textView!.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: textView!, top: 24, left: 24, bottom: 24, right: 24)
MaterialLayout.alignToParent(view, child: textView!, top: 124, left: 24, bottom: 24, right: 24)
}
func textWillProcessEdit(text: Text, textStorage: TextStorage, string: String, range: NSRange) {
......
......@@ -173,16 +173,16 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
/**
:name: contentInsets
*/
public var contentInsets: MaterialEdgeInsets = .None {
public var contentInsetPreset: MaterialEdgeInsets = .None {
didSet {
contentInsetsRef = MaterialEdgeInsetsToValue(contentInsets)
contentInset = MaterialEdgeInsetsToValue(contentInsetPreset)
}
}
/**
:name: contentInsetsRef
:name: contentInset
*/
public var contentInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square4) {
public var contentInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square4) {
didSet {
reloadView()
}
......@@ -287,16 +287,16 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
previewView.frame = bounds
if let v: UIButton = cameraButton {
v.frame.origin.y = bounds.height - contentInsetsRef.bottom - v.bounds.height
v.frame.origin.x = contentInsetsRef.left
v.frame.origin.y = bounds.height - contentInset.bottom - v.bounds.height
v.frame.origin.x = contentInset.left
}
if let v: UIButton = captureButton {
v.frame.origin.y = bounds.height - contentInsetsRef.bottom - v.bounds.height
v.frame.origin.y = bounds.height - contentInset.bottom - v.bounds.height
v.frame.origin.x = (bounds.width - v.bounds.width) / 2
}
if let v: UIButton = videoButton {
v.frame.origin.y = bounds.height - contentInsetsRef.bottom - v.bounds.height
v.frame.origin.x = bounds.width - v.bounds.width - contentInsetsRef.right
v.frame.origin.y = bounds.height - contentInset.bottom - v.bounds.height
v.frame.origin.x = bounds.width - v.bounds.width - contentInset.right
}
if let v: AVCaptureConnection = (previewView.layer as! AVCaptureVideoPreviewLayer).connection {
v.videoOrientation = captureSession.currentVideoOrientation
......
......@@ -45,16 +45,16 @@ public class CardView : MaterialPulseView {
/**
:name: dividerInsets
*/
public var dividerInsets: MaterialEdgeInsets = .None {
public var dividerInsetPreset: MaterialEdgeInsets = .None {
didSet {
dividerInsetsRef = MaterialEdgeInsetsToValue(dividerInsets)
dividerInset = MaterialEdgeInsetsToValue(dividerInsetPreset)
}
}
/**
:name: dividerInsetsRef
:name: dividerInset
*/
public var dividerInsetsRef: UIEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0) {
public var dividerInset: UIEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0) {
didSet {
reloadView()
}
......@@ -63,16 +63,16 @@ public class CardView : MaterialPulseView {
/**
:name: contentInsets
*/
public var contentInsets: MaterialEdgeInsets = .None {
public var contentInsetPreset: MaterialEdgeInsets = .None {
didSet {
contentInsetsRef = MaterialEdgeInsetsToValue(contentInsets)
contentInset = MaterialEdgeInsetsToValue(contentInsetPreset)
}
}
/**
:name: contentInsetsRef
:name: contentInset
*/
public var contentInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
public var contentInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
didSet {
reloadView()
}
......@@ -81,16 +81,16 @@ public class CardView : MaterialPulseView {
/**
:name: titleLabelInsets
*/
public var titleLabelInsets: MaterialEdgeInsets = .None {
public var titleLabelInsetPreset: MaterialEdgeInsets = .None {
didSet {
titleLabelInsetsRef = MaterialEdgeInsetsToValue(titleLabelInsets)
titleLabelInset = MaterialEdgeInsetsToValue(titleLabelInsetPreset)
}
}
/**
:name: titleLabelInsetsRef
:name: titleLabelInset
*/
public var titleLabelInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
public var titleLabelInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
didSet {
reloadView()
}
......@@ -109,16 +109,16 @@ public class CardView : MaterialPulseView {
/**
:name: detailLabelInsets
*/
public var detailLabelInsets: MaterialEdgeInsets = .None {
public var detailLabelInsetPreset: MaterialEdgeInsets = .None {
didSet {
detailLabelInsetsRef = MaterialEdgeInsetsToValue(detailLabelInsets)
detailLabelInset = MaterialEdgeInsetsToValue(detailLabelInsetPreset)
}
}
/**
:name: detailLabelInsetsRef
:name: detailLabelInset
*/
public var detailLabelInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
public var detailLabelInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
didSet {
reloadView()
}
......@@ -137,16 +137,16 @@ public class CardView : MaterialPulseView {
/**
:name: leftButtonsInsets
*/
public var leftButtonsInsets: MaterialEdgeInsets = .None {
public var leftButtonsInsetPreset: MaterialEdgeInsets = .None {
didSet {
leftButtonsInsetsRef = MaterialEdgeInsetsToValue(leftButtonsInsets)
leftButtonsInset = MaterialEdgeInsetsToValue(leftButtonsInsetPreset)
}
}
/**
:name: leftButtonsInsetsRef
:name: leftButtonsInset
*/
public var leftButtonsInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.None) {
public var leftButtonsInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.None) {
didSet {
reloadView()
}
......@@ -169,16 +169,16 @@ public class CardView : MaterialPulseView {
/**
:name: rightButtonsInsets
*/
public var rightButtonsInsets: MaterialEdgeInsets = .None {
public var rightButtonsInsetPreset: MaterialEdgeInsets = .None {
didSet {
rightButtonsInsetsRef = MaterialEdgeInsetsToValue(rightButtonsInsets)
rightButtonsInset = MaterialEdgeInsetsToValue(rightButtonsInsetPreset)
}
}
/**
:name: rightButtonsInsetsRef
:name: rightButtonsInset
*/
public var rightButtonsInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.None) {
public var rightButtonsInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.None) {
didSet {
reloadView()
}
......@@ -234,11 +234,11 @@ public class CardView : MaterialPulseView {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
if divider {
var y: CGFloat = contentInsetsRef.bottom + dividerInsetsRef.bottom
var y: CGFloat = contentInset.bottom + dividerInset.bottom
if 0 < leftButtons?.count {
y += leftButtonsInsetsRef.top + leftButtonsInsetsRef.bottom + leftButtons![0].frame.height
y += leftButtonsInset.top + leftButtonsInset.bottom + leftButtons![0].frame.height
} else if 0 < rightButtons?.count {
y += rightButtonsInsetsRef.top + rightButtonsInsetsRef.bottom + rightButtons![0].frame.height
y += rightButtonsInset.top + rightButtonsInset.bottom + rightButtons![0].frame.height
}
if 0 < y {
prepareDivider(bounds.height - y - 0.5, width: bounds.width)
......@@ -266,10 +266,10 @@ public class CardView : MaterialPulseView {
if nil != titleLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef.top + titleLabelInsetsRef.top
metrics["insetTop"] = contentInset.top + titleLabelInset.top
} else if nil != detailLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef.top + detailLabelInsetsRef.top
metrics["insetTop"] = contentInset.top + detailLabelInset.top
}
// title
......@@ -279,7 +279,7 @@ public class CardView : MaterialPulseView {
verticalFormat += "-[titleLabel]"
views["titleLabel"] = v
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + titleLabelInsetsRef.left, right: contentInsetsRef.right + titleLabelInsetsRef.right)
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInset.left + titleLabelInset.left, right: contentInset.right + titleLabelInset.right)
}
// detail
......@@ -287,16 +287,16 @@ public class CardView : MaterialPulseView {
addSubview(v)
if nil == titleLabel {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + detailLabelInsetsRef.top
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + detailLabelInset.top
} else {
verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInsetsRef.bottom + detailLabelInsetsRef.top
metrics["insetB"] = titleLabelInset.bottom + detailLabelInset.top
}
verticalFormat += "-[detailLabel]"
views["detailLabel"] = v
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + detailLabelInsetsRef.left, right: contentInsetsRef.right + detailLabelInsetsRef.right)
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInset.left + detailLabelInset.left, right: contentInset.right + detailLabelInset.right)
}
// leftButtons
......@@ -319,10 +319,10 @@ public class CardView : MaterialPulseView {
h += "[\(k)]"
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef.bottom + leftButtonsInsetsRef.bottom)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInset.bottom + leftButtonsInset.bottom)
}
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : contentInsetsRef.left + leftButtonsInsetsRef.left, "left_right" : leftButtonsInsetsRef.left + leftButtonsInsetsRef.right], views: d))
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : contentInset.left + leftButtonsInset.left, "left_right" : leftButtonsInset.left + leftButtonsInset.right], views: d))
}
}
......@@ -347,39 +347,39 @@ public class CardView : MaterialPulseView {
}
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef.bottom + rightButtonsInsetsRef.bottom)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInset.bottom + rightButtonsInset.bottom)
}
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : contentInsetsRef.right + rightButtonsInsetsRef.right, "right_left" : rightButtonsInsetsRef.right + rightButtonsInsetsRef.left], views: d))
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : contentInset.right + rightButtonsInset.right, "right_left" : rightButtonsInset.right + rightButtonsInset.left], views: d))
}
}
if 0 < leftButtons?.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0]
metrics["insetC"] = leftButtonsInsetsRef.top
metrics["insetBottom"] = contentInsetsRef.bottom + leftButtonsInsetsRef.bottom
metrics["insetC"] = leftButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = rightButtons![0]
metrics["insetC"] = rightButtonsInsetsRef.top
metrics["insetBottom"] = contentInsetsRef.bottom + rightButtonsInsetsRef.bottom
metrics["insetC"] = rightButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
}
if nil != detailLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef.bottom + detailLabelInsetsRef.bottom + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetBottom"] = contentInset.bottom + detailLabelInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInsetsRef.bottom + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
}
} else if nil != titleLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef.bottom + titleLabelInsetsRef.bottom + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetBottom"] = contentInset.bottom + titleLabelInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} else {
metrics["insetC"] = (metrics["insetTop"] as! CGFloat) + titleLabelInsetsRef.bottom + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetC"] = (metrics["insetTop"] as! CGFloat) + titleLabelInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
}
} else if nil != metrics["insetC"] {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInsetsRef.top + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0)
}
......@@ -409,7 +409,7 @@ public class CardView : MaterialPulseView {
layer.addSublayer(dividerLayer!)
}
dividerLayer?.backgroundColor = dividerColor?.CGColor
dividerLayer?.frame = CGRectMake(dividerInsetsRef.left, y, width - dividerInsetsRef.left - dividerInsetsRef.right, 1)
dividerLayer?.frame = CGRectMake(dividerInset.left, y, width - dividerInset.left - dividerInset.right, 1)
}
/**
......
......@@ -31,6 +31,6 @@ public class FlatButton : MaterialButton {
setTitleColor(MaterialColor.blue.accent3, forState: .Normal)
pulseColor = MaterialColor.blue.accent3
cornerRadius = .Radius1
contentInsets = .WideRectangle3
contentInsetPreset = .WideRectangle3
}
}
\ No newline at end of file
......@@ -45,16 +45,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: dividerInsets
*/
public var dividerInsets: MaterialEdgeInsets = .None {
public var dividerInsetPreset: MaterialEdgeInsets = .None {
didSet {
dividerInsetsRef = MaterialEdgeInsetsToValue(dividerInsets)
dividerInset = MaterialEdgeInsetsToValue(dividerInsetPreset)
}
}
/**
:name: dividerInsetsRef
:name: dividerInset
*/
public var dividerInsetsRef: UIEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0) {
public var dividerInset: UIEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0) {
didSet {
reloadView()
}
......@@ -153,16 +153,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: contentInsets
*/
public var contentInsets: MaterialEdgeInsets = .None {
public var contentInsetPreset: MaterialEdgeInsets = .None {
didSet {
contentInsetsRef = MaterialEdgeInsetsToValue(contentInsets)
contentInset = MaterialEdgeInsetsToValue(contentInsetPreset)
}
}
/**
:name: contentInsetsRef
:name: contentInset
*/
public var contentInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
public var contentInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
didSet {
reloadView()
}
......@@ -171,16 +171,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: titleLabelInsets
*/
public var titleLabelInsets: MaterialEdgeInsets = .None {
public var titleLabelInsetPreset: MaterialEdgeInsets = .None {
didSet {
titleLabelInsetsRef = MaterialEdgeInsetsToValue(titleLabelInsets)
titleLabelInset = MaterialEdgeInsetsToValue(titleLabelInsetPreset)
}
}
/**
:name: titleLabelInsetsRef
:name: titleLabelInset
*/
public var titleLabelInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
public var titleLabelInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
didSet {
reloadView()
}
......@@ -199,16 +199,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: detailLabelInsets
*/
public var detailLabelInsets: MaterialEdgeInsets = .None {
public var detailLabelInsetPreset: MaterialEdgeInsets = .None {
didSet {
detailLabelInsetsRef = MaterialEdgeInsetsToValue(detailLabelInsets)
detailLabelInset = MaterialEdgeInsetsToValue(detailLabelInsetPreset)
}
}
/**
:name: detailLabelInsetsRef
:name: detailLabelInset
*/
public var detailLabelInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
public var detailLabelInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
didSet {
reloadView()
}
......@@ -227,16 +227,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: leftButtonsInsets
*/
public var leftButtonsInsets: MaterialEdgeInsets = .None {
public var leftButtonsInsetPreset: MaterialEdgeInsets = .None {
didSet {
leftButtonsInsetsRef = MaterialEdgeInsetsToValue(leftButtonsInsets)
leftButtonsInset = MaterialEdgeInsetsToValue(leftButtonsInsetPreset)
}
}
/**
:name: leftButtonsInsetsRef
:name: leftButtonsInset
*/
public var leftButtonsInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.None) {
public var leftButtonsInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.None) {
didSet {
reloadView()
}
......@@ -259,16 +259,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: rightButtonsInsets
*/
public var rightButtonsInsets: MaterialEdgeInsets = .None {
public var rightButtonsInsetPreset: MaterialEdgeInsets = .None {
didSet {
rightButtonsInsetsRef = MaterialEdgeInsetsToValue(rightButtonsInsets)
rightButtonsInset = MaterialEdgeInsetsToValue(rightButtonsInsetPreset)
}
}
/**
:name: rightButtonsInsetsRef
:name: rightButtonsInset
*/
public var rightButtonsInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.None) {
public var rightButtonsInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.None) {
didSet {
reloadView()
}
......@@ -328,11 +328,11 @@ public class ImageCardView : MaterialPulseView {
// divider
if divider {
var y: CGFloat = contentInsetsRef.bottom + dividerInsetsRef.bottom
var y: CGFloat = contentInset.bottom + dividerInset.bottom
if 0 < leftButtons?.count {
y += leftButtonsInsetsRef.top + leftButtonsInsetsRef.bottom + leftButtons![0].frame.height
y += leftButtonsInset.top + leftButtonsInset.bottom + leftButtons![0].frame.height
} else if 0 < rightButtons?.count {
y += rightButtonsInsetsRef.top + rightButtonsInsetsRef.bottom + rightButtons![0].frame.height
y += rightButtonsInset.top + rightButtonsInset.bottom + rightButtons![0].frame.height
}
if 0 < y {
prepareDivider(bounds.height - y - 0.5, width: bounds.width)
......@@ -363,10 +363,10 @@ public class ImageCardView : MaterialPulseView {
metrics["insetTop"] = imageLayer!.frame.height
} else if nil != titleLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef.top + titleLabelInsetsRef.top
metrics["insetTop"] = contentInset.top + titleLabelInset.top
} else if nil != detailLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef.top + detailLabelInsetsRef.top
metrics["insetTop"] = contentInset.top + detailLabelInset.top
}
// title
......@@ -377,9 +377,9 @@ public class ImageCardView : MaterialPulseView {
verticalFormat += "-[titleLabel]"
views["titleLabel"] = v
} else {
MaterialLayout.alignFromTop(self, child: v, top: contentInsetsRef.top + titleLabelInsetsRef.top)
MaterialLayout.alignFromTop(self, child: v, top: contentInset.top + titleLabelInset.top)
}
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + titleLabelInsetsRef.left, right: contentInsetsRef.right + titleLabelInsetsRef.right)
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInset.left + titleLabelInset.left, right: contentInset.right + titleLabelInset.right)
}
// detail
......@@ -388,15 +388,15 @@ public class ImageCardView : MaterialPulseView {
if nil == imageLayer?.contents && nil != titleLabel {
verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInsetsRef.bottom + detailLabelInsetsRef.top
metrics["insetB"] = titleLabelInset.bottom + detailLabelInset.top
} else {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + detailLabelInsetsRef.top
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + detailLabelInset.top
}
verticalFormat += "-[detailLabel]"
views["detailLabel"] = v
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + detailLabelInsetsRef.left, right: contentInsetsRef.right + detailLabelInsetsRef.right)
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInset.left + detailLabelInset.left, right: contentInset.right + detailLabelInset.right)
}
// leftButtons
......@@ -419,10 +419,10 @@ public class ImageCardView : MaterialPulseView {
h += "[\(k)]"
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef.bottom + leftButtonsInsetsRef.bottom)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInset.bottom + leftButtonsInset.bottom)
}
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : contentInsetsRef.left + leftButtonsInsetsRef.left, "left_right" : leftButtonsInsetsRef.left + leftButtonsInsetsRef.right], views: d))
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : contentInset.left + leftButtonsInset.left, "left_right" : leftButtonsInset.left + leftButtonsInset.right], views: d))
}
}
......@@ -447,10 +447,10 @@ public class ImageCardView : MaterialPulseView {
}
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef.bottom + rightButtonsInsetsRef.bottom)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInset.bottom + rightButtonsInset.bottom)
}
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : contentInsetsRef.right + rightButtonsInsetsRef.right, "right_left" : rightButtonsInsetsRef.right + rightButtonsInsetsRef.left], views: d))
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : contentInset.right + rightButtonsInset.right, "right_left" : rightButtonsInset.right + rightButtonsInset.left], views: d))
}
}
......@@ -458,59 +458,59 @@ public class ImageCardView : MaterialPulseView {
if 0 < leftButtons?.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0]
metrics["insetC"] = leftButtonsInsetsRef.top
metrics["insetBottom"] = contentInsetsRef.bottom + leftButtonsInsetsRef.bottom
metrics["insetC"] = leftButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = rightButtons![0]
metrics["insetC"] = rightButtonsInsetsRef.top
metrics["insetBottom"] = contentInsetsRef.bottom + rightButtonsInsetsRef.bottom
metrics["insetC"] = rightButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
}
if nil != detailLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef.bottom + detailLabelInsetsRef.bottom + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetBottom"] = contentInset.bottom + detailLabelInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInsetsRef.bottom + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
}
} else if nil != titleLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef.bottom + titleLabelInsetsRef.bottom + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetBottom"] = contentInset.bottom + titleLabelInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + titleLabelInsetsRef.bottom + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + titleLabelInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
}
} else if nil != metrics["insetC"] {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInsetsRef.top + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0)
}
} else if nil != detailLabel {
if 0 < leftButtons?.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0]
metrics["insetC"] = leftButtonsInsetsRef.top
metrics["insetBottom"] = contentInsetsRef.bottom + leftButtonsInsetsRef.bottom
metrics["insetC"] = leftButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = rightButtons![0]
metrics["insetC"] = rightButtonsInsetsRef.top
metrics["insetBottom"] = contentInsetsRef.bottom + rightButtonsInsetsRef.bottom
metrics["insetC"] = rightButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
}
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef.bottom + detailLabelInsetsRef.bottom + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetBottom"] = contentInset.bottom + detailLabelInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInsetsRef.bottom + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
}
} else {
if 0 < leftButtons?.count {
verticalFormat += "-[button]"
views["button"] = leftButtons![0]
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentInsetsRef.top + leftButtonsInsetsRef.top + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetBottom"] = contentInsetsRef.bottom + leftButtonsInsetsRef.bottom
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentInset.top + leftButtonsInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0)
metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count {
verticalFormat += "-[button]"
views["button"] = rightButtons![0]
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentInsetsRef.top + rightButtonsInsetsRef.top + (divider ? dividerInsetsRef.top + dividerInsetsRef.bottom : 0)
metrics["insetBottom"] = contentInsetsRef.bottom + rightButtonsInsetsRef.bottom
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentInset.top + rightButtonsInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0)
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
} else {
if translatesAutoresizingMaskIntoConstraints {
addConstraints(MaterialLayout.constraint("V:[view(height)]", options: [], metrics: ["height": imageLayer!.frame.height], views: ["view": self]))
......@@ -558,7 +558,7 @@ public class ImageCardView : MaterialPulseView {
layer.addSublayer(dividerLayer!)
}
dividerLayer?.backgroundColor = dividerColor?.CGColor
dividerLayer?.frame = CGRectMake(dividerInsetsRef.left, y, width - dividerInsetsRef.left - dividerInsetsRef.right, 1)
dividerLayer?.frame = CGRectMake(dividerInset.left, y, width - dividerInset.left - dividerInset.right, 1)
}
/**
......
......@@ -276,9 +276,9 @@ public class MaterialButton : UIButton {
/**
:name: contentInsets
*/
public var contentInsets: MaterialEdgeInsets {
public var contentInsetPreset: MaterialEdgeInsets {
didSet {
let value: UIEdgeInsets = MaterialEdgeInsetsToValue(contentInsets)
let value: UIEdgeInsets = MaterialEdgeInsetsToValue(contentInsetPreset)
contentEdgeInsets = UIEdgeInsetsMake(value.top, value.left, value.bottom, value.right)
}
}
......@@ -292,7 +292,7 @@ public class MaterialButton : UIButton {
depth = .None
shape = .None
cornerRadius = .None
contentInsets = .None
contentInsetPreset = .None
super.init(coder: aDecoder)
prepareView()
}
......@@ -308,7 +308,7 @@ public class MaterialButton : UIButton {
depth = .None
shape = .None
cornerRadius = .None
contentInsets = .None
contentInsetPreset = .None
super.init(frame: frame)
prepareView()
}
......@@ -318,7 +318,7 @@ public class MaterialButton : UIButton {
self.init(frame: CGRectNull)
}
/// Overriding the layout callback for layer sublayers.
/// Overriding the layout callback for sublayers.
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
......
......@@ -325,7 +325,7 @@ public class MaterialView : UIView {
self.init(frame: CGRectNull)
}
/// Overriding the layout callback for layer sublayers.
/// Overriding the layout callback for sublayers.
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
......
......@@ -31,16 +31,16 @@ public class NavigationBarView : MaterialView {
/**
:name: contentInsets
*/
public var contentInsets: MaterialEdgeInsets = .None {
public var contentInsetPreset: MaterialEdgeInsets = .None {
didSet {
contentInsetsRef = MaterialEdgeInsetsToValue(contentInsets)
contentInset = MaterialEdgeInsetsToValue(contentInsetPreset)
}
}
/**
:name: contentInsetsRef
:name: contentInset
*/
public var contentInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
public var contentInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.Square2) {
didSet {
reloadView()
}
......@@ -49,16 +49,16 @@ public class NavigationBarView : MaterialView {
/**
:name: titleLabelInsets
*/
public var titleLabelInsets: MaterialEdgeInsets = .None {
public var titleLabelInsetPreset: MaterialEdgeInsets = .None {
didSet {
titleLabelInsetsRef = MaterialEdgeInsetsToValue(titleLabelInsets)
titleLabelInset = MaterialEdgeInsetsToValue(titleLabelInsetPreset)
}
}
/**
:name: titleLabelInsetsRef
:name: titleLabelInset
*/
public var titleLabelInsetsRef: UIEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 0, right: 0) {
public var titleLabelInset: UIEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 0, right: 0) {
didSet {
reloadView()
}
......@@ -77,16 +77,16 @@ public class NavigationBarView : MaterialView {
/**
:name: detailLabelInsets
*/
public var detailLabelInsets: MaterialEdgeInsets = .None {
public var detailLabelInsetPreset: MaterialEdgeInsets = .None {
didSet {
detailLabelInsetsRef = MaterialEdgeInsetsToValue(detailLabelInsets)
detailLabelInset = MaterialEdgeInsetsToValue(detailLabelInsetPreset)
}
}
/**
:name: detailLabelInsetsRef
:name: detailLabelInset
*/
public var detailLabelInsetsRef: UIEdgeInsets = MaterialEdgeInsetsToValue(.None) {
public var detailLabelInset: UIEdgeInsets = MaterialEdgeInsetsToValue(.None) {
didSet {
reloadView()
}
......@@ -105,16 +105,16 @@ public class NavigationBarView : MaterialView {
/**
:name: leftButtonsInsets
*/
public var leftButtonsInsets: MaterialEdgeInsets = .None {
public var leftButtonsInsetPreset: MaterialEdgeInsets = .None {
didSet {
leftButtonsInsetsRef = MaterialEdgeInsetsToValue(leftButtonsInsets)
leftButtonsInset = MaterialEdgeInsetsToValue(leftButtonsInsetPreset)
}
}
/**
:name: leftButtonsInsetsRef
:name: leftButtonsInset
*/
public var leftButtonsInsetsRef: UIEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 0, right: 0) {
public var leftButtonsInset: UIEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 0, right: 0) {
didSet {
reloadView()
}
......@@ -137,16 +137,16 @@ public class NavigationBarView : MaterialView {
/**
:name: rightButtonsInsets
*/
public var rightButtonsInsets: MaterialEdgeInsets = .None {
public var rightButtonsInsetPreset: MaterialEdgeInsets = .None {
didSet {
rightButtonsInsetsRef = MaterialEdgeInsetsToValue(rightButtonsInsets)
rightButtonsInset = MaterialEdgeInsetsToValue(rightButtonsInsetPreset)
}
}
/**
:name: rightButtonsInsetsRef
:name: rightButtonsInset
*/
public var rightButtonsInsetsRef: UIEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 0, right: 0) {
public var rightButtonsInset: UIEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 0, right: 0) {
didSet {
reloadView()
}
......@@ -211,10 +211,10 @@ public class NavigationBarView : MaterialView {
if nil != titleLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef.top + titleLabelInsetsRef.top
metrics["insetTop"] = contentInset.top + titleLabelInset.top
} else if nil != detailLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef.top + detailLabelInsetsRef.top
metrics["insetTop"] = contentInset.top + detailLabelInset.top
}
// title
......@@ -223,21 +223,21 @@ public class NavigationBarView : MaterialView {
views["titleLabel"] = v
addSubview(v)
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + titleLabelInsetsRef.left, right: contentInsetsRef.right + titleLabelInsetsRef.right)
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInset.left + titleLabelInset.left, right: contentInset.right + titleLabelInset.right)
}
// detail
if let v = detailLabel {
if nil != titleLabel {
verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInsetsRef.bottom + detailLabelInsetsRef.top
metrics["insetB"] = titleLabelInset.bottom + detailLabelInset.top
}
verticalFormat += "-[detailLabel]"
views["detailLabel"] = v
addSubview(v)
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + detailLabelInsetsRef.left, right: contentInsetsRef.right + detailLabelInsetsRef.right)
MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInset.left + detailLabelInset.left, right: contentInset.right + detailLabelInset.right)
}
// leftButtons
......@@ -260,10 +260,10 @@ public class NavigationBarView : MaterialView {
h += "[\(k)]"
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef.bottom + leftButtonsInsetsRef.bottom)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInset.bottom + leftButtonsInset.bottom)
}
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : contentInsetsRef.left + leftButtonsInsetsRef.left, "left_right" : leftButtonsInsetsRef.left + leftButtonsInsetsRef.right], views: d))
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : contentInset.left + leftButtonsInset.left, "left_right" : leftButtonsInset.left + leftButtonsInset.right], views: d))
}
}
......@@ -288,24 +288,24 @@ public class NavigationBarView : MaterialView {
}
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef.bottom + rightButtonsInsetsRef.bottom)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInset.bottom + rightButtonsInset.bottom)
}
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : contentInsetsRef.right + rightButtonsInsetsRef.right, "right_left" : rightButtonsInsetsRef.right + rightButtonsInsetsRef.left], views: d))
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : contentInset.right + rightButtonsInset.right, "right_left" : rightButtonsInset.right + rightButtonsInset.left], views: d))
}
}
if nil != detailLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef.bottom + detailLabelInsetsRef.bottom
metrics["insetBottom"] = contentInset.bottom + detailLabelInset.bottom
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInsetsRef.bottom
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInset.bottom
}
} else if nil != titleLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef.bottom + titleLabelInsetsRef.bottom
metrics["insetBottom"] = contentInset.bottom + titleLabelInset.bottom
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + titleLabelInsetsRef.bottom
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + titleLabelInset.bottom
}
}
......
......@@ -32,6 +32,6 @@ public class RaisedButton : MaterialButton {
backgroundColor = MaterialColor.blue.accent3
depth = .Depth2
cornerRadius = .Radius1
contentInsets = .WideRectangle3
contentInsetPreset = .WideRectangle3
}
}
\ No newline at end of file
......@@ -24,6 +24,21 @@ public class TextField : UITextField {
/// The bottom border layer.
public private(set) lazy var bottomBorderLayer: CAShapeLayer = CAShapeLayer()
/**
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using
the image property, then this value does not need to be set, since the
visualLayer's maskToBounds is set to true by default.
*/
public var masksToBounds: Bool {
get {
return layer.masksToBounds
}
set(value) {
layer.masksToBounds = value
}
}
/// A property that accesses the backing layer's backgroundColor.
public override var backgroundColor: UIColor? {
didSet {
......@@ -63,6 +78,9 @@ public class TextField : UITextField {
}
set(value) {
layer.frame.size.width = value
if .None != shape {
layer.frame.size.height = value
}
}
}
......@@ -78,11 +96,98 @@ public class TextField : UITextField {
}
set(value) {
layer.frame.size.height = value
if .None != shape {
layer.frame.size.width = value
}
}
}
/// A property that accesses the backing layer's shadowColor.
public var shadowColor: UIColor? {
didSet {
layer.shadowColor = shadowColor?.CGColor
}
}
/// A property that accesses the backing layer's shadowOffset.
public var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
}
}
/// A property that accesses the backing layer's shadowOpacity.
public var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
}
}
/// A property that accesses the backing layer's shadowRadius.
public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
}
}
/**
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 {
didSet {
let value: MaterialDepthType = MaterialDepthToValue(depth)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
}
}
/**
A property that sets the cornerRadius of the backing layer. If the shape
property has a value of .Circle when the cornerRadius is set, it will
become .None, as it no longer maintains its circle shape.
*/
public var cornerRadius: MaterialRadius {
didSet {
if let v: MaterialRadius = cornerRadius {
layer.cornerRadius = MaterialRadiusToValue(v)
if .Circle == shape {
shape = .None
}
}
}
}
/**
A property that accesses the layer.borderWith using a MaterialBorder
A property that manages the overall shape for the object. If either the
width or height property is set, the other will be automatically adjusted
to maintain the shape of the object.
*/
public var shape: MaterialShape {
didSet {
if .None != shape {
if width < height {
frame.size.width = height
} else {
frame.size.height = width
}
}
}
}
/**
A property that accesses the layer.borderWith using a MaterialBorder
enum preset.
*/
public var borderWidth: MaterialBorder {
......@@ -119,36 +224,35 @@ public class TextField : UITextField {
}
/**
:name: titleLabelNormalColor
The title UILabel that is displayed when there is text. The
titleLabel text value is updated with the placeholder text
value before being displayed.
*/
public var titleLabelNormalColor: UIColor? {
public var titleLabel: UILabel? {
didSet {
titleLabel?.textColor = titleLabelNormalColor
bottomBorderLayer.backgroundColor = titleLabelNormalColor?.CGColor
prepareTitleLabel()
}
}
/**
:name: titleLabelHighlightedColor
*/
public var titleLabelHighlightedColor: UIColor?
/// The color of the titleLabel text when the textField is not active.
public var titleLabelTextColor: UIColor? {
didSet {
titleLabel?.textColor = titleLabelTextColor
bottomBorderLayer.backgroundColor = titleLabelTextColor?.CGColor
}
}
/**
:name: detailLabelHighlightedColor
*/
public var detailLabelHighlightedColor: UIColor?
/// The color of the titleLabel text when the textField is active.
public var titleLabelActiveTextColor: UIColor?
/**
:name: titleLabel
:name: detailLabelActiveTextColor
*/
public var titleLabel: UILabel? {
didSet {
prepareTitleLabel()
}
}
public var detailLabelActiveTextColor: UIColor?
/**
:name: detailLabel
The detail UILabel that is displayed when the detailLabelHidden property
is set to false.
*/
public var detailLabel: UILabel? {
didSet {
......@@ -162,11 +266,11 @@ public class TextField : UITextField {
public var detailLabelHidden: Bool = false {
didSet {
if detailLabelHidden {
bottomBorderLayer.backgroundColor = editing ? titleLabelHighlightedColor?.CGColor : titleLabelNormalColor?.CGColor
bottomBorderLayer.backgroundColor = editing ? titleLabelActiveTextColor?.CGColor : titleLabelTextColor?.CGColor
hideDetailLabel()
} else {
detailLabel?.textColor = detailLabelHighlightedColor
bottomBorderLayer.backgroundColor = detailLabelHighlightedColor?.CGColor
detailLabel?.textColor = detailLabelActiveTextColor
bottomBorderLayer.backgroundColor = detailLabelActiveTextColor?.CGColor
showDetailLabel()
}
}
......@@ -176,6 +280,9 @@ public class TextField : UITextField {
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
depth = .None
shape = .None
cornerRadius = .None
borderWidth = .None
super.init(coder: aDecoder)
prepareView()
......@@ -185,6 +292,9 @@ public class TextField : UITextField {
:name: init
*/
public override init(frame: CGRect) {
depth = .None
shape = .None
cornerRadius = .None
borderWidth = .None
super.init(frame: frame)
prepareView()
......@@ -197,21 +307,79 @@ public class TextField : UITextField {
self.init(frame: CGRectNull)
}
/**
:name: layoutSublayersOfLayer
*/
/// Overriding the layout callback for sublayers.
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
bottomBorderLayer.frame = CGRectMake(0, bounds.height + 8, bounds.width, 1)
layoutShape()
}
}
/**
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 {
MaterialAnimation.animationDisabled {
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
}
}
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
layer.removeAnimationForKey(a.keyPath!)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
}
/**
:name: prepareView
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.
*/
public func prepareView() {
clipsToBounds = false
backgroundColor = MaterialColor.white
shadowColor = MaterialColor.black
borderColor = MaterialColor.black
masksToBounds = false
prepareBottomBorderLayer()
}
......@@ -221,12 +389,12 @@ public class TextField : UITextField {
internal func textFieldDidBegin(textField: TextField) {
titleLabel?.text = placeholder
if 0 == text?.utf16.count {
titleLabel?.textColor = titleLabelNormalColor
bottomBorderLayer.backgroundColor = titleLabelNormalColor?.CGColor
titleLabel?.textColor = titleLabelTextColor
bottomBorderLayer.backgroundColor = titleLabelTextColor?.CGColor
detailLabelHidden = true
} else {
titleLabel?.textColor = titleLabelHighlightedColor
bottomBorderLayer.backgroundColor = detailLabelHidden ? titleLabelHighlightedColor?.CGColor : detailLabelHighlightedColor?.CGColor
titleLabel?.textColor = titleLabelActiveTextColor
bottomBorderLayer.backgroundColor = detailLabelHidden ? titleLabelActiveTextColor?.CGColor : detailLabelActiveTextColor?.CGColor
}
}
......@@ -236,8 +404,8 @@ public class TextField : UITextField {
internal func textFieldDidChange(textField: TextField) {
if 0 < text?.utf16.count {
showTitleLabel()
titleLabel?.textColor = titleLabelHighlightedColor
bottomBorderLayer.backgroundColor = detailLabelHidden ? titleLabelHighlightedColor?.CGColor : detailLabelHighlightedColor?.CGColor
titleLabel?.textColor = titleLabelActiveTextColor
bottomBorderLayer.backgroundColor = detailLabelHidden ? titleLabelActiveTextColor?.CGColor : detailLabelActiveTextColor?.CGColor
} else if 0 == text?.utf16.count {
hideTitleLabel()
detailLabelHidden = true
......@@ -253,8 +421,15 @@ public class TextField : UITextField {
} else if 0 == text?.utf16.count {
hideTitleLabel()
}
titleLabel?.textColor = titleLabelNormalColor
bottomBorderLayer.backgroundColor = detailLabelHidden ? titleLabelNormalColor?.CGColor : detailLabelHighlightedColor?.CGColor
titleLabel?.textColor = titleLabelTextColor
bottomBorderLayer.backgroundColor = detailLabelHidden ? titleLabelTextColor?.CGColor : detailLabelActiveTextColor?.CGColor
}
/// Manages the layout for the shape of the view instance.
internal func layoutShape() {
if .Circle == shape {
layer.cornerRadius = width / 2
}
}
/**
......
......@@ -21,51 +21,228 @@ import UIKit
public protocol TextViewDelegate : UITextViewDelegate {}
public class TextView: UITextView {
public var titleLabel: UILabel? {
/**
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using
the image property, then this value does not need to be set, since the
visualLayer's maskToBounds is set to true by default.
*/
public var masksToBounds: Bool {
get {
return layer.masksToBounds
}
set(value) {
layer.masksToBounds = value
}
}
/// A property that accesses the backing layer's backgroundColor.
public override var backgroundColor: UIColor? {
didSet {
prepareTitleLabel()
layer.backgroundColor = backgroundColor?.CGColor
}
}
/// A property that accesses the layer.frame.origin.x property.
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.
public var y: CGFloat {
get {
return layer.frame.origin.y
}
set(value) {
layer.frame.origin.y = value
}
}
/**
A property that accesses the layer.frame.origin.width property.
When setting this property in conjunction with the shape property having a
value that is not .None, the height will be adjusted to maintain the correct
shape.
*/
public var width: CGFloat {
get {
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
if .None != shape {
layer.frame.size.height = value
}
}
}
/**
:name: titleLabelNormalColor
A property that accesses the layer.frame.origin.height property.
When setting this property in conjunction with the shape property having a
value that is not .None, the width will be adjusted to maintain the correct
shape.
*/
public var titleLabelNormalColor: UIColor? {
public var height: CGFloat {
get {
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
if .None != shape {
layer.frame.size.width = value
}
}
}
/// A property that accesses the backing layer's shadowColor.
public var shadowColor: UIColor? {
didSet {
titleLabel?.textColor = titleLabelNormalColor
layer.shadowColor = shadowColor?.CGColor
}
}
/// A property that accesses the backing layer's shadowOffset.
public var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
}
}
/// A property that accesses the backing layer's shadowOpacity.
public var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
}
}
/// A property that accesses the backing layer's shadowRadius.
public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
}
}
/**
:name: titleLabelHighlightedColor
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 titleLabelHighlightedColor: UIColor?
public var depth: MaterialDepth {
didSet {
let value: MaterialDepthType = MaterialDepthToValue(depth)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
}
}
/**
:name: init
A property that sets the cornerRadius of the backing layer. If the shape
property has a value of .Circle when the cornerRadius is set, it will
become .None, as it no longer maintains its circle shape.
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
public var cornerRadius: MaterialRadius {
didSet {
if let v: MaterialRadius = cornerRadius {
layer.cornerRadius = MaterialRadiusToValue(v)
if .Circle == shape {
shape = .None
}
}
}
}
/**
:name: init
A property that manages the overall shape for the object. If either the
width or height property is set, the other will be automatically adjusted
to maintain the shape of the object.
*/
public override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
prepareView()
public var shape: MaterialShape {
didSet {
if .None != shape {
if width < height {
frame.size.width = height
} else {
frame.size.height = width
}
}
}
}
//
// :name: deinit
//
deinit {
removeNotificationHandlers()
/**
A property that accesses the layer.borderWith using a MaterialBorder
enum preset.
*/
public var borderWidth: MaterialBorder {
didSet {
layer.borderWidth = MaterialBorderToValue(borderWidth)
}
}
/// A property that accesses the layer.borderColor property.
public var borderColor: UIColor? {
didSet {
layer.borderColor = borderColor?.CGColor
}
}
/// A property that accesses the layer.position property.
public var position: CGPoint {
get {
return layer.position
}
set(value) {
layer.position = value
}
}
/// A property that accesses the layer.zPosition property.
public var zPosition: CGFloat {
get {
return layer.zPosition
}
set(value) {
layer.zPosition = value
}
}
/**
:name: placeholderLabel
The title UILabel that is displayed when there is text. The
titleLabel text value is updated with the placeholderLabel
text value before being displayed.
*/
public var titleLabel: UILabel? {
didSet {
prepareTitleLabel()
}
}
/// The color of the titleLabel text when the textView is not active.
public var titleLabelTextColor: UIColor? {
didSet {
titleLabel?.textColor = titleLabelTextColor
}
}
/// The color of the titleLabel text when the textView is active.
public var titleLabelActiveTextColor: UIColor?
/**
:name: placeholderLabel
*/
public var placeholderLabel: UILabel? {
didSet {
......@@ -75,7 +252,7 @@ public class TextView: UITextView {
/**
:name: text
:name: text
*/
public override var text: String! {
didSet {
......@@ -84,7 +261,7 @@ public class TextView: UITextView {
}
/**
:name: attributedText
:name: attributedText
*/
public override var attributedText: NSAttributedString! {
didSet {
......@@ -93,7 +270,16 @@ public class TextView: UITextView {
}
/**
:name: textContainerInset
:name: textContainerInset
*/
public var textContainerInsetPreset: MaterialEdgeInsets = .None {
didSet {
textContainerInset = MaterialEdgeInsetsToValue(textContainerInsetPreset)
}
}
/**
:name: textContainerInset
*/
public override var textContainerInset: UIEdgeInsets {
didSet {
......@@ -101,12 +287,104 @@ public class TextView: UITextView {
}
}
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
depth = .None
shape = .None
cornerRadius = .None
borderWidth = .None
super.init(coder: aDecoder)
prepareView()
}
/**
:name: init
*/
public override init(frame: CGRect, textContainer: NSTextContainer?) {
depth = .None
shape = .None
cornerRadius = .None
borderWidth = .None
super.init(frame: frame, textContainer: textContainer)
prepareView()
}
//
// :name: deinit
//
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.
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
layoutShape()
}
}
/**
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 {
MaterialAnimation.animationDisabled {
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
}
}
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
layer.removeAnimationForKey(a.keyPath!)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
}
/**
:name: reloadView
*/
......@@ -128,9 +406,9 @@ public class TextView: UITextView {
internal func handleTextViewTextDidBegin() {
titleLabel?.text = placeholderLabel?.text
if 0 == text?.utf16.count {
titleLabel?.textColor = titleLabelNormalColor
titleLabel?.textColor = titleLabelTextColor
} else {
titleLabel?.textColor = titleLabelHighlightedColor
titleLabel?.textColor = titleLabelActiveTextColor
}
}
......@@ -144,7 +422,7 @@ public class TextView: UITextView {
if 0 < text?.utf16.count {
showTitleLabel()
titleLabel?.textColor = titleLabelHighlightedColor
titleLabel?.textColor = titleLabelActiveTextColor
} else if 0 == text?.utf16.count {
hideTitleLabel()
}
......@@ -159,16 +437,23 @@ public class TextView: UITextView {
} else if 0 == text?.utf16.count {
hideTitleLabel()
}
titleLabel?.textColor = titleLabelNormalColor
titleLabel?.textColor = titleLabelTextColor
}
/// Manages the layout for the shape of the view instance.
internal func layoutShape() {
if .Circle == shape {
layer.cornerRadius = width / 2
}
}
//
// :name: prepareView
//
private func prepareView() {
textContainerInset = UIEdgeInsets(top: 24, left: 0, bottom: 24, right: 0)
backgroundColor = MaterialColor.clear
clipsToBounds = false
textContainerInset = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
backgroundColor = MaterialColor.white
masksToBounds = false
removeNotificationHandlers()
prepareNotificationHandlers()
reloadView()
......@@ -180,7 +465,7 @@ public class TextView: UITextView {
v.font = font
v.textAlignment = textAlignment
v.numberOfLines = 0
v.backgroundColor = .clearColor()
v.backgroundColor = MaterialColor.clear
titleLabel?.text = placeholderLabel?.text
addSubview(v)
reloadView()
......@@ -188,9 +473,7 @@ public class TextView: UITextView {
}
}
/**
:name: prepareTitleLabel
*/
/// Prepares the titleLabel property.
private func prepareTitleLabel() {
if let v: UILabel = titleLabel {
MaterialAnimation.animationDisabled {
......@@ -204,9 +487,7 @@ public class TextView: UITextView {
}
}
/**
:name: showTitleLabel
*/
/// Shows and animates the titleLabel property.
private func showTitleLabel() {
if let v: UILabel = titleLabel {
v.frame.size.height = v.font.pointSize
......@@ -218,9 +499,7 @@ public class TextView: UITextView {
}
}
/**
:name: hideTitleLabel
*/
/// Hides and animates the titleLabel property.
private func hideTitleLabel() {
if let v: UILabel = titleLabel {
UIView.animateWithDuration(0.25, animations: {
......@@ -232,12 +511,14 @@ public class TextView: UITextView {
}
}
/// Prepares the Notification handlers.
private func prepareNotificationHandlers() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleTextViewTextDidBegin", name: UITextViewTextDidBeginEditingNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleTextViewTextDidChange", name: UITextViewTextDidChangeNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleTextViewTextDidEnd", name: UITextViewTextDidEndEditingNotification, object: nil)
}
/// Removes the Notification handlers.
private func removeNotificationHandlers() {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidBeginEditingNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidChangeNotification, 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