Commit ad0a7302 by Daniel Dahan

general updates and improvements

parent 159f7a6c
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>childOrder</key>
<array>
<string>Source</string>
<string>Tests</string>
</array>
<key>createMarkedFile</key>
<false/>
<key>sheetClusters</key>
<array>
<array>
<string>README.md</string>
</array>
</array>
</dict>
</plist>
...@@ -2,16 +2,16 @@ ...@@ -2,16 +2,16 @@
### CocoaPods Support ### CocoaPods Support
MaterialKit is on CocoaPods under the name [MK](https://cocoapods.org/?q=MK). MaterialKit is on CocoaPods under the name [MK][1].
### Basic MaterialView ### Basic MaterialView
To get started, let's introduce MaterialView, a lightweight UIView Object that has flexibility in mind. Common controls have been added to make things easier. For example, let's make a circle view that has a shadow, border, and image. To get started, let's introduce MaterialView, a lightweight UIView Object that has flexibility in mind. Common controls have been added to make things easier. For example, let's make a circle view that has a shadow, border, and image.
![MaterialKitPreview](http://www.materialkit.io/github/img1.png) ![MaterialKitPreview][image-1]
```swift ```swift
let v: MaterialView = MaterialView(frame: CGRectMake(100, 100, 200, 200)) `let v: MaterialView = MaterialView(frame: CGRectMake(100, 100, 200, 200))
v.shape = .Circle v.shape = .Circle
v.shadowDepth = .Depth2 v.shadowDepth = .Depth2
v.borderWidth = .Border1 v.borderWidth = .Border1
...@@ -20,15 +20,15 @@ v.image = UIImage(named: "focus") ...@@ -20,15 +20,15 @@ v.image = UIImage(named: "focus")
// Add to UIViewController. // Add to UIViewController.
view.addSubview(v) view.addSubview(v)
``` ```
`
### Animated MaterialPulseView ### Animated MaterialPulseView
Let's expand on the basic MaterialView and use an animated MaterialPulseView. In this example, we will make the shape a square with some rounded corners. Let's expand on the basic MaterialView and use an animated MaterialPulseView. In this example, we will make the shape a square with some rounded corners.
![MaterialKitPreview](http://www.materialkit.io/github/img2.gif) ![MaterialKitPreview][image-2]
```swift ```swift
let v: MaterialPulseView = MaterialPulseView(frame: CGRectMake(100, 100, 200, 200)) `let v: MaterialPulseView = MaterialPulseView(frame: CGRectMake(100, 100, 200, 200))
v.shape = .Square v.shape = .Square
v.cornerRadius = .Radius2 v.cornerRadius = .Radius2
v.shadowDepth = .Depth2 v.shadowDepth = .Depth2
...@@ -37,60 +37,60 @@ v.image = UIImage(named: "focus") ...@@ -37,60 +37,60 @@ v.image = UIImage(named: "focus")
// Add to UIViewController. // Add to UIViewController.
view.addSubview(v) view.addSubview(v)
``` ```
`
### Simple FlatButton ### Simple FlatButton
A FlatButton is the best place to start when introducing MaterialKit buttons. It is simple, clean, and very effective. Below is an example of a FlatButton in action. A FlatButton is the best place to start when introducing MaterialKit buttons. It is simple, clean, and very effective. Below is an example of a FlatButton in action.
![MaterialKitPreview](http://www.materialkit.io/github/img3.gif) ![MaterialKitPreview][image-3]
```swift ```swift
let v: FlatButton = FlatButton(frame: CGRectMake(100, 100, 200, 64)) `let v: FlatButton = FlatButton(frame: CGRectMake(100, 100, 200, 64))
v.setTitle("Flat", forState: .Normal) v.setTitle("Flat", forState: .Normal)
v.titleLabel!.font = RobotoFont.mediumWithSize(32) v.titleLabel!.font = RobotoFont.mediumWithSize(32)
// Add to UIViewController. // Add to UIViewController.
view.addSubview(v) view.addSubview(v)
``` ```
`
### Noticeable RaisedButton ### Noticeable RaisedButton
A RaisedButton is sure to get attention. Take a look at the following code sample. A RaisedButton is sure to get attention. Take a look at the following code sample.
![MaterialKitPreview](http://www.materialkit.io/github/img4.gif) ![MaterialKitPreview][image-4]
```swift ```swift
let v: RaisedButton = RaisedButton(frame: CGRectMake(100, 100, 200, 64)) `let v: RaisedButton = RaisedButton(frame: CGRectMake(100, 100, 200, 64))
v.setTitle("Raised", forState: .Normal) v.setTitle("Raised", forState: .Normal)
v.titleLabel!.font = RobotoFont.mediumWithSize(32) v.titleLabel!.font = RobotoFont.mediumWithSize(32)
// Add to UIViewController. // Add to UIViewController.
view.addSubview(v) view.addSubview(v)
``` ```
`
### Actionable FabButton ### Actionable FabButton
A FabButton is essential to Material Design's overall look. I leave this example as simple as possible to showcase its beauty. A FabButton is essential to Material Design's overall look. I leave this example as simple as possible to showcase its beauty.
![MaterialKitPreview](http://www.materialkit.io/github/img5.gif) ![MaterialKitPreview][image-5]
```swift ```swift
let v: FabButton = FabButton(frame: CGRectMake(100, 100, 64, 64)) `let v: FabButton = FabButton(frame: CGRectMake(100, 100, 64, 64))
v.setImage(UIImage(named: "ic_create_white"), forState: .Normal) v.setImage(UIImage(named: "ic\_create\_white"), forState: .Normal)
v.setImage(UIImage(named: "ic_create_white"), forState: .Highlighted) v.setImage(UIImage(named: "ic\_create\_white"), forState: .Highlighted)
// Add to UIViewController. // Add to UIViewController.
view.addSubview(v) view.addSubview(v)
``` ```
`
### Sleek NavigationBarView ### Sleek NavigationBarView
A NavigationBarView is a very common UI element and the more presentable it is, the better. The following example shows how to setup a NavigationBarView on the fly. A NavigationBarView is a very common UI element and the more presentable it is, the better. The following example shows how to setup a NavigationBarView on the fly.
![MaterialKitPreview](http://www.materialkit.io/github/img6.gif) ![MaterialKitPreview][image-6]
```swift ```swift
let v: NavigationBarView = NavigationBarView(titleLabel: MaterialLabel())! `let v: NavigationBarView = NavigationBarView(titleLabel: MaterialLabel())!
v.backgroundColor = MaterialColor.blue.accent3 v.backgroundColor = MaterialColor.blue.accent3
v.statusBarStyle = .LightContent v.statusBarStyle = .LightContent
...@@ -126,15 +126,15 @@ v.rightButtons = [b3, b4] ...@@ -126,15 +126,15 @@ v.rightButtons = [b3, b4]
// Add to UIViewController. // Add to UIViewController.
view.addSubview(v) view.addSubview(v)
``` ```
`
### Flexible BasicCardView ### Flexible BasicCardView
A BasicCardView is super flexible with all its options - including a title, detail, left buttons, and right buttons. Below is an example of a simple setup. A BasicCardView is super flexible with all its options - including a title, detail, left buttons, and right buttons. Below is an example of a simple setup.
![MaterialKitPreview](http://www.materialkit.io/github/img7.gif) ![MaterialKitPreview][image-7]
```swift ```swift
let v: BasicCardView = BasicCardView(titleLabel: UILabel(), detailLabel: UILabel())! `let v: BasicCardView = BasicCardView(titleLabel: UILabel(), detailLabel: UILabel())!
v.backgroundColor = MaterialColor.blueGrey.darken1 v.backgroundColor = MaterialColor.blueGrey.darken1
v.dividerColor = MaterialColor.blueGrey.base v.dividerColor = MaterialColor.blueGrey.base
...@@ -166,13 +166,13 @@ v.translatesAutoresizingMaskIntoConstraints = false ...@@ -166,13 +166,13 @@ v.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParentHorizontallyWithInsets(view, child: v, left: 20, right: 20) MaterialLayout.alignToParentHorizontallyWithInsets(view, child: v, left: 20, right: 20)
MaterialLayout.alignFromTop(view, child: v, top: 100) MaterialLayout.alignFromTop(view, child: v, top: 100)
``` ```
`
A BasicCardView can easily add an image as its background, below is the code that shows how to do this. A BasicCardView can easily add an image as its background, below is the code that shows how to do this.
![MaterialKitPreview](http://www.materialkit.io/github/img8.gif) ![MaterialKitPreview][image-8]
```swift ```swift
let v: BasicCardView = BasicCardView(titleLabel: UILabel(), detailLabel: UILabel())! `let v: BasicCardView = BasicCardView(titleLabel: UILabel(), detailLabel: UILabel())!
v.image = UIImage(named: "forest") v.image = UIImage(named: "forest")
...@@ -190,15 +190,15 @@ v.translatesAutoresizingMaskIntoConstraints = false ...@@ -190,15 +190,15 @@ v.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParentHorizontallyWithInsets(view, child: v, left: 20, right: 20) MaterialLayout.alignToParentHorizontallyWithInsets(view, child: v, left: 20, right: 20)
MaterialLayout.alignFromTop(view, child: v, top: 100) MaterialLayout.alignFromTop(view, child: v, top: 100)
``` ```
`
### Easy MaterialAnimation ### Easy MaterialAnimation
Animations are a wonderful way to add life to your application. MaterialAnimation is a lightweight API for constructing complex animations. Below is an example of an animation. Animations are a wonderful way to add life to your application. MaterialAnimation is a lightweight API for constructing complex animations. Below is an example of an animation.
![MaterialKitPreview](http://www.materialkit.io/github/img9.gif) ![MaterialKitPreview][image-9]
```swift ```swift
let v: MaterialPulseView = MaterialPulseView(frame: CGRectMake(50, 50, 200, 200)) `let v: MaterialPulseView = MaterialPulseView(frame: CGRectMake(50, 50, 200, 200))
v.shape = .Circle v.shape = .Circle
v.shadowDepth = .Depth2 v.shadowDepth = .Depth2
v.borderWidth = .Border1 v.borderWidth = .Border1
...@@ -209,19 +209,34 @@ view.addSubview(v) ...@@ -209,19 +209,34 @@ view.addSubview(v)
// Play a group of animations. // Play a group of animations.
v.animation(MaterialAnimation.animationGroup([ v.animation(MaterialAnimation.animationGroup([
MaterialAnimation.rotation(3), MaterialAnimation.rotation(3),
MaterialAnimation.position(CGPointMake(225, 400)), MaterialAnimation.position(CGPointMake(225, 400)),
MaterialAnimation.cornerRadius(30), MaterialAnimation.cornerRadius(30),
MaterialAnimation.backgroundColor(MaterialColor.red.darken1) MaterialAnimation.backgroundColor(MaterialColor.red.darken1)
], duration: 1)) ], duration: 1))
``` ```
`### License
### License [AGPLv3][2]
[AGPLv3](http://choosealicense.com/licenses/agpl-3.0/)
### Contributors ### Contributors
* [Daniel Dahan](https://github.com/danieldahan) * [Daniel Dahan][3]
* [Adam Dahan](https://github.com/adamdahan) * [Adam Dahan][4]
* [Michael Reyder](https://github.com/michaelReyder) * [Michael Reyder][5]
[1]: https://cocoapods.org/?q=MK
[2]: http://choosealicense.com/licenses/agpl-3.0/
[3]: https://github.com/danieldahan
[4]: https://github.com/adamdahan
[5]: https://github.com/michaelReyder
[image-1]: http://www.materialkit.io/github/img1.png
[image-2]: http://www.materialkit.io/github/img2.gif
[image-3]: http://www.materialkit.io/github/img3.gif
[image-4]: http://www.materialkit.io/github/img4.gif
[image-5]: http://www.materialkit.io/github/img5.gif
[image-6]: http://www.materialkit.io/github/img6.gif
[image-7]: http://www.materialkit.io/github/img7.gif
[image-8]: http://www.materialkit.io/github/img8.gif
[image-9]: http://www.materialkit.io/github/img9.gif
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>createMarkedFile</key>
<false/>
<key>sheetClusters</key>
<array>
<array>
<string>BasicCardView.swift</string>
</array>
<array>
<string>FabButton.swift</string>
</array>
<array>
<string>FlatButton.swift</string>
</array>
<array>
<string>MaterialAnimation.swift</string>
</array>
<array>
<string>MaterialBasicAnimation.swift</string>
</array>
<array>
<string>MaterialBorder.swift</string>
</array>
<array>
<string>MaterialButton.swift</string>
</array>
<array>
<string>MaterialColor.swift</string>
</array>
<array>
<string>MaterialDepth.swift</string>
</array>
<array>
<string>MaterialFont.swift</string>
</array>
<array>
<string>MaterialGravity.swift</string>
</array>
<array>
<string>MaterialInsets.swift</string>
</array>
<array>
<string>MaterialKeyframeAnimation.swift</string>
</array>
<array>
<string>MaterialLabel.swift</string>
</array>
<array>
<string>MaterialLayer.swift</string>
</array>
<array>
<string>MaterialLayout.swift</string>
</array>
<array>
<string>MaterialPulseView.swift</string>
</array>
<array>
<string>MaterialRadius.swift</string>
</array>
<array>
<string>MaterialShape.swift</string>
</array>
<array>
<string>MaterialStatusBarStyle.swift</string>
</array>
<array>
<string>MaterialTheme.swift</string>
</array>
<array>
<string>MaterialView.swift</string>
</array>
<array>
<string>NavigationBarView.swift</string>
</array>
<array>
<string>RaisedButton.swift</string>
</array>
<array>
<string>RobotoFont.swift</string>
</array>
</array>
</dict>
</plist>
...@@ -86,9 +86,7 @@ public class BasicCardView : MaterialPulseView { ...@@ -86,9 +86,7 @@ public class BasicCardView : MaterialPulseView {
*/ */
public var titleLabel: UILabel? { public var titleLabel: UILabel? {
didSet { didSet {
if let v = titleLabel { titleLabel?.translatesAutoresizingMaskIntoConstraints = false
v.translatesAutoresizingMaskIntoConstraints = false
}
reloadView() reloadView()
} }
} }
...@@ -117,9 +115,7 @@ public class BasicCardView : MaterialPulseView { ...@@ -117,9 +115,7 @@ public class BasicCardView : MaterialPulseView {
*/ */
public var detailLabel: UILabel? { public var detailLabel: UILabel? {
didSet { didSet {
if let v = detailLabel { detailLabel?.translatesAutoresizingMaskIntoConstraints = false
v.translatesAutoresizingMaskIntoConstraints = false
}
reloadView() reloadView()
} }
} }
...@@ -216,7 +212,7 @@ public class BasicCardView : MaterialPulseView { ...@@ -216,7 +212,7 @@ public class BasicCardView : MaterialPulseView {
*/ */
public convenience init?(titleLabel: UILabel? = nil, detailLabel: UILabel? = nil, leftButtons: Array<MaterialButton>? = nil, rightButtons: Array<MaterialButton>? = nil) { public convenience init?(titleLabel: UILabel? = nil, detailLabel: UILabel? = nil, leftButtons: Array<MaterialButton>? = nil, rightButtons: Array<MaterialButton>? = nil) {
self.init(frame: CGRectNull) self.init(frame: CGRectNull)
self.prepareProperties(titleLabel, detailLabel: detailLabel, leftButtons: leftButtons, rightButtons: rightButtons) prepareProperties(titleLabel, detailLabel: detailLabel, leftButtons: leftButtons, rightButtons: rightButtons)
} }
/** /**
...@@ -269,7 +265,6 @@ public class BasicCardView : MaterialPulseView { ...@@ -269,7 +265,6 @@ public class BasicCardView : MaterialPulseView {
views["titleLabel"] = v views["titleLabel"] = v
addSubview(v) addSubview(v)
v.layer.zPosition = 2000
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + titleLabelInsetsRef!.left, right: contentInsetsRef!.right + titleLabelInsetsRef!.right) MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + titleLabelInsetsRef!.left, right: contentInsetsRef!.right + titleLabelInsetsRef!.right)
} }
...@@ -284,7 +279,6 @@ public class BasicCardView : MaterialPulseView { ...@@ -284,7 +279,6 @@ public class BasicCardView : MaterialPulseView {
views["detailLabel"] = v views["detailLabel"] = v
addSubview(v) addSubview(v)
v.layer.zPosition = 2000
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + detailLabelInsetsRef!.left, right: contentInsetsRef!.right + detailLabelInsetsRef!.right) MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + detailLabelInsetsRef!.left, right: contentInsetsRef!.right + detailLabelInsetsRef!.right)
} }
...@@ -294,18 +288,24 @@ public class BasicCardView : MaterialPulseView { ...@@ -294,18 +288,24 @@ public class BasicCardView : MaterialPulseView {
var h: String = "H:|" var h: String = "H:|"
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var i: Int = 0 var i: Int = 0
for b in v { for b in v {
let k: String = "b\(i++)" let k: String = "b\(i)"
d[k] = b d[k] = b
h += "-(left)-[\(k)]"
if 0 == i++ {
h += "-(left)-"
} else {
h += "-(left_right)-"
}
h += "[\(k)]"
addSubview(b) addSubview(b)
b.layer.zPosition = 2000
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef!.bottom + leftButtonsInsetsRef!.bottom) MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef!.bottom + leftButtonsInsetsRef!.bottom)
} }
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : leftButtonsInsetsRef!.left], views: d)) addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : leftButtonsInsetsRef!.left, "left_right" : leftButtonsInsetsRef!.left + leftButtonsInsetsRef!.right], views: d))
} }
} }
...@@ -317,16 +317,23 @@ public class BasicCardView : MaterialPulseView { ...@@ -317,16 +317,23 @@ public class BasicCardView : MaterialPulseView {
var i: Int = 0 var i: Int = 0
for b in v { for b in v {
let k: String = "b\(i++)" let k: String = "b\(i)"
d[k] = b d[k] = b
h += "[\(k)]-(right)-"
h += "[\(k)]"
if 0 == i++ {
h += "-(right_left)-"
} else {
h += "-(right)-"
}
addSubview(b) addSubview(b)
b.layer.zPosition = 2000
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef!.bottom + rightButtonsInsetsRef!.bottom) MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef!.bottom + rightButtonsInsetsRef!.bottom)
} }
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : rightButtonsInsetsRef!.right], views: d)) addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : rightButtonsInsetsRef!.right, "right_left" : rightButtonsInsetsRef!.right + rightButtonsInsetsRef!.left], views: d))
} }
} }
...@@ -370,7 +377,7 @@ public class BasicCardView : MaterialPulseView { ...@@ -370,7 +377,7 @@ public class BasicCardView : MaterialPulseView {
dividerLayer = CAShapeLayer() dividerLayer = CAShapeLayer()
dividerLayer!.backgroundColor = dividerColor?.CGColor dividerLayer!.backgroundColor = dividerColor?.CGColor
dividerLayer!.frame = CGRectMake(0, y, width, 1) dividerLayer!.frame = CGRectMake(0, y, width, 1)
dividerLayer!.zPosition = 900 dividerLayer!.zPosition = 0
layer.addSublayer(dividerLayer!) layer.addSublayer(dividerLayer!)
} }
} }
......
...@@ -47,9 +47,8 @@ public class MaterialButton : UIButton { ...@@ -47,9 +47,8 @@ public class MaterialButton : UIButton {
/** /**
:name: pulseColorOpacity :name: pulseColorOpacity
*/ */
public var pulseColorOpacity: CGFloat! { public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity {
didSet { didSet {
pulseColorOpacity = nil == pulseColorOpacity ? 0.25 : pulseColorOpacity!
preparePulseLayer() preparePulseLayer()
} }
} }
...@@ -67,11 +66,8 @@ public class MaterialButton : UIButton { ...@@ -67,11 +66,8 @@ public class MaterialButton : UIButton {
:name: backgroundColor :name: backgroundColor
*/ */
public override var backgroundColor: UIColor? { public override var backgroundColor: UIColor? {
get { didSet {
return nil == layer.backgroundColor ? nil : UIColor(CGColor: layer.backgroundColor!) layer.backgroundColor = backgroundColor?.CGColor
}
set(value) {
layer.backgroundColor = value?.CGColor
} }
} }
...@@ -108,7 +104,7 @@ public class MaterialButton : UIButton { ...@@ -108,7 +104,7 @@ public class MaterialButton : UIButton {
} }
set(value) { set(value) {
layer.frame.size.width = value layer.frame.size.width = value
if nil != shape { if .None != shape {
layer.frame.size.height = value layer.frame.size.height = value
} }
} }
...@@ -123,7 +119,7 @@ public class MaterialButton : UIButton { ...@@ -123,7 +119,7 @@ public class MaterialButton : UIButton {
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
if nil != shape { if .None != shape {
layer.frame.size.width = value layer.frame.size.width = value
} }
} }
...@@ -132,56 +128,70 @@ public class MaterialButton : UIButton { ...@@ -132,56 +128,70 @@ public class MaterialButton : UIButton {
/** /**
:name: shadowColor :name: shadowColor
*/ */
public var shadowColor: UIColor! { public var shadowColor: UIColor? {
didSet { didSet {
layer.shadowColor = nil == shadowColor ? MaterialColor.clear.CGColor : shadowColor!.CGColor layer.shadowColor = shadowColor?.CGColor
} }
} }
/** /**
:name: shadowOffset :name: shadowOffset
*/ */
public var shadowOffset: CGSize! { public var shadowOffset: CGSize {
didSet { get {
layer.shadowOffset = nil == shadowOffset ? CGSizeMake(0, 0) : shadowOffset! return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
} }
} }
/** /**
:name: shadowOpacity :name: shadowOpacity
*/ */
public var shadowOpacity: Float! { public var shadowOpacity: Float {
didSet { get {
layer.shadowOpacity = nil == shadowOpacity ? 0 : shadowOpacity! return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
} }
} }
/** /**
:name: shadowRadius :name: shadowRadius
*/ */
public var shadowRadius: CGFloat! { public var shadowRadius: CGFloat {
didSet { get {
layer.shadowRadius = nil == shadowRadius ? 0 : shadowRadius! return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
} }
} }
/** /**
:name: masksToBounds :name: masksToBounds
*/ */
public var masksToBounds: Bool! { public var masksToBounds: Bool {
didSet { get {
visualLayer.masksToBounds = nil == masksToBounds ? false : masksToBounds! return visualLayer.masksToBounds
}
set(value) {
visualLayer.masksToBounds = value
} }
} }
/** /**
:name: cornerRadius :name: cornerRadius
*/ */
public var cornerRadius: MaterialRadius! { public var cornerRadius: MaterialRadius? {
didSet { didSet {
layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .None : cornerRadius!) if let v: MaterialRadius = cornerRadius {
if .Circle == shape { layer.cornerRadius = MaterialRadiusToValue(v)
shape = nil if .Circle == shape {
shape = .None
}
} }
} }
} }
...@@ -189,9 +199,9 @@ public class MaterialButton : UIButton { ...@@ -189,9 +199,9 @@ public class MaterialButton : UIButton {
/** /**
:name: shape :name: shape
*/ */
public var shape: MaterialShape? { public var shape: MaterialShape {
didSet { didSet {
if nil != shape { if .None != shape {
if width < height { if width < height {
layer.frame.size.width = height layer.frame.size.width = height
} else { } else {
...@@ -204,27 +214,27 @@ public class MaterialButton : UIButton { ...@@ -204,27 +214,27 @@ public class MaterialButton : UIButton {
/** /**
:name: borderWidth :name: borderWidth
*/ */
public var borderWidth: MaterialBorder! { public var borderWidth: MaterialBorder {
didSet { didSet {
layer.borderWidth = MaterialBorderToValue(nil == borderWidth ? .None : borderWidth!) layer.borderWidth = MaterialBorderToValue(borderWidth)
} }
} }
/** /**
:name: borderColor :name: borderColor
*/ */
public var borderColor: UIColor! { public var borderColor: UIColor? {
didSet { didSet {
layer.borderColor = nil == borderColor ? MaterialColor.clear.CGColor : borderColor!.CGColor layer.borderColor = borderColor?.CGColor
} }
} }
/** /**
:name: shadowDepth :name: shadowDepth
*/ */
public var shadowDepth: MaterialDepth! { public var shadowDepth: MaterialDepth {
didSet { didSet {
let value: MaterialDepthType = MaterialDepthToValue(nil == shadowDepth ? .None : shadowDepth!) let value: MaterialDepthType = MaterialDepthToValue(shadowDepth)
shadowOffset = value.offset shadowOffset = value.offset
shadowOpacity = value.opacity shadowOpacity = value.opacity
shadowRadius = value.radius shadowRadius = value.radius
...@@ -246,18 +256,21 @@ public class MaterialButton : UIButton { ...@@ -246,18 +256,21 @@ public class MaterialButton : UIButton {
/** /**
:name: zPosition :name: zPosition
*/ */
public var zPosition: CGFloat! { public var zPosition: CGFloat {
didSet { get {
layer.zPosition = zPosition return layer.zPosition
}
set(value) {
layer.zPosition = value
} }
} }
/** /**
:name: contentInsets :name: contentInsets
*/ */
public var contentInsets: MaterialInsets! { public var contentInsets: MaterialInsets {
didSet { didSet {
let value: MaterialInsetsType = MaterialInsetsToValue(nil == contentInsets ? .None : contentInsets) let value: MaterialInsetsType = MaterialInsetsToValue(contentInsets)
contentEdgeInsets = UIEdgeInsetsMake(value.top, value.left, value.bottom, value.right) contentEdgeInsets = UIEdgeInsetsMake(value.top, value.left, value.bottom, value.right)
} }
} }
...@@ -266,6 +279,10 @@ public class MaterialButton : UIButton { ...@@ -266,6 +279,10 @@ public class MaterialButton : UIButton {
:name: init :name: init
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
borderWidth = .None
shadowDepth = .None
shape = .None
contentInsets = .None
super.init(coder: aDecoder) super.init(coder: aDecoder)
} }
...@@ -273,6 +290,10 @@ public class MaterialButton : UIButton { ...@@ -273,6 +290,10 @@ public class MaterialButton : UIButton {
:name: init :name: init
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
borderWidth = .None
shadowDepth = .None
shape = .None
contentInsets = .None
super.init(frame: frame) super.init(frame: frame)
prepareView() prepareView()
} }
...@@ -373,7 +394,7 @@ public class MaterialButton : UIButton { ...@@ -373,7 +394,7 @@ public class MaterialButton : UIButton {
let s: CGFloat = (width < height ? height : width) / 2 let s: CGFloat = (width < height ? height : width) / 2
let f: CGFloat = 3 let f: CGFloat = 3
let v: CGFloat = s / f let v: CGFloat = s / f
let d: CGFloat = pulseFill ? 5 * f : 2 * f let d: CGFloat = pulseFill ? 5 * f : 2.5 * f
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled({
self.pulseLayer.hidden = false self.pulseLayer.hidden = false
self.pulseLayer.bounds = CGRectMake(0, 0, v, v) self.pulseLayer.bounds = CGRectMake(0, 0, v, v)
...@@ -434,7 +455,7 @@ public class MaterialButton : UIButton { ...@@ -434,7 +455,7 @@ public class MaterialButton : UIButton {
// visualLayer // visualLayer
visualLayer.zPosition = -1 visualLayer.zPosition = -1
layer.addSublayer(visualLayer) layer.addSublayer(visualLayer)
// pulseLayer // pulseLayer
pulseLayer.hidden = true pulseLayer.hidden = true
pulseLayer.zPosition = 1 pulseLayer.zPosition = 1
...@@ -454,7 +475,7 @@ public class MaterialButton : UIButton { ...@@ -454,7 +475,7 @@ public class MaterialButton : UIButton {
// :name: preparePulseLayer // :name: preparePulseLayer
// //
internal func preparePulseLayer() { internal func preparePulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity!).CGColor pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
} }
// //
......
...@@ -26,10 +26,12 @@ public enum MaterialInsets { ...@@ -26,10 +26,12 @@ public enum MaterialInsets {
case Square2 case Square2
case Square3 case Square3
case Square4 case Square4
case Square5
case Rectangle1 case Rectangle1
case Rectangle2 case Rectangle2
case Rectangle3 case Rectangle3
case Rectangle4 case Rectangle4
case Rectangle5
} }
/** /**
...@@ -47,6 +49,8 @@ public func MaterialInsetsToValue(inset: MaterialInsets) -> MaterialInsetsType { ...@@ -47,6 +49,8 @@ public func MaterialInsetsToValue(inset: MaterialInsets) -> MaterialInsetsType {
return (top: 16, left: 16, bottom: 16, right: 16) return (top: 16, left: 16, bottom: 16, right: 16)
case .Square4: case .Square4:
return (top: 32, left: 32, bottom: 32, right: 32) return (top: 32, left: 32, bottom: 32, right: 32)
case .Square5:
return (top: 64, left: 64, bottom: 64, right: 64)
case .Rectangle1: case .Rectangle1:
return (top: 2, left: 4, bottom: 2, right: 4) return (top: 2, left: 4, bottom: 2, right: 4)
case .Rectangle2: case .Rectangle2:
...@@ -55,5 +59,7 @@ public func MaterialInsetsToValue(inset: MaterialInsets) -> MaterialInsetsType { ...@@ -55,5 +59,7 @@ public func MaterialInsetsToValue(inset: MaterialInsets) -> MaterialInsetsType {
return (top: 8, left: 16, bottom: 8, right: 16) return (top: 8, left: 16, bottom: 8, right: 16)
case .Rectangle4: case .Rectangle4:
return (top: 16, left: 32, bottom: 16, right: 32) return (top: 16, left: 32, bottom: 16, right: 32)
case .Rectangle5:
return (top: 32, left: 64, bottom: 32, right: 64)
} }
} }
...@@ -42,9 +42,8 @@ public class MaterialPulseView : MaterialView { ...@@ -42,9 +42,8 @@ public class MaterialPulseView : MaterialView {
/** /**
:name: pulseColorOpacity :name: pulseColorOpacity
*/ */
public var pulseColorOpacity: CGFloat! { public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity {
didSet { didSet {
pulseColorOpacity = nil == pulseColorOpacity ? 0.25 : pulseColorOpacity!
preparePulseLayer() preparePulseLayer()
} }
} }
...@@ -54,7 +53,6 @@ public class MaterialPulseView : MaterialView { ...@@ -54,7 +53,6 @@ public class MaterialPulseView : MaterialView {
*/ */
public var pulseColor: UIColor? { public var pulseColor: UIColor? {
didSet { didSet {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity!).CGColor
preparePulseLayer() preparePulseLayer()
} }
} }
...@@ -130,7 +128,6 @@ public class MaterialPulseView : MaterialView { ...@@ -130,7 +128,6 @@ public class MaterialPulseView : MaterialView {
super.prepareView() super.prepareView()
userInteractionEnabled = MaterialTheme.pulseView.userInteractionEnabled userInteractionEnabled = MaterialTheme.pulseView.userInteractionEnabled
backgroundColor = MaterialTheme.pulseView.backgroundColor backgroundColor = MaterialTheme.pulseView.backgroundColor
pulseColorOpacity = MaterialTheme.pulseView.pulseColorOpacity
pulseColor = MaterialTheme.pulseView.pulseColor pulseColor = MaterialTheme.pulseView.pulseColor
contentsRect = MaterialTheme.pulseView.contentsRect contentsRect = MaterialTheme.pulseView.contentsRect
...@@ -155,7 +152,7 @@ public class MaterialPulseView : MaterialView { ...@@ -155,7 +152,7 @@ public class MaterialPulseView : MaterialView {
// :name: preparePulseLayer // :name: preparePulseLayer
// //
internal func preparePulseLayer() { internal func preparePulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity!).CGColor pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
} }
// //
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
// //
public enum MaterialShape { public enum MaterialShape {
case None
case Square case Square
case Circle case Circle
} }
...@@ -103,8 +103,8 @@ public extension MaterialTheme.basicCardView { ...@@ -103,8 +103,8 @@ public extension MaterialTheme.basicCardView {
public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square3) public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square3)
public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2) public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var detailLabelInsetsRef: MaterialInsetsType = (top: 0, left: 8, bottom: 16, right: 8) public static var detailLabelInsetsRef: MaterialInsetsType = (top: 0, left: 8, bottom: 16, right: 8)
public static var leftButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 16, bottom: -8, right: 0) public static var leftButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 8, bottom: -8, right: 0)
public static var rightButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: -8, right: 16) public static var rightButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: -8, right: 8)
// border // border
public static var borderWidth: MaterialBorder = .None public static var borderWidth: MaterialBorder = .None
...@@ -147,9 +147,11 @@ public extension MaterialTheme.navigationBarView { ...@@ -147,9 +147,11 @@ public extension MaterialTheme.navigationBarView {
// shape // shape
public static var masksToBounds: Bool = true public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = .None public static var cornerRadius: MaterialRadius = .None
public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Rectangle3) public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var leftButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2) public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.None)
public static var rightButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2) public static var detailLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.None)
public static var leftButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 8, bottom: 0, right: 0)
public static var rightButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: 0, right: 8)
// border // border
public static var borderWidth: MaterialBorder = .None public static var borderWidth: MaterialBorder = .None
...@@ -195,7 +197,7 @@ public extension MaterialTheme.flatButton { ...@@ -195,7 +197,7 @@ public extension MaterialTheme.flatButton {
public static var masksToBounds: Bool = true public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = .Radius1 public static var cornerRadius: MaterialRadius = .Radius1
public static var contentInsets: MaterialInsets = .Rectangle3 public static var contentInsets: MaterialInsets = .Rectangle3
public static var shape: MaterialShape? = nil public static var shape: MaterialShape = .None
// border // border
public static var borderWidth: MaterialBorder = .None public static var borderWidth: MaterialBorder = .None
...@@ -227,7 +229,7 @@ public extension MaterialTheme.raisedButton { ...@@ -227,7 +229,7 @@ public extension MaterialTheme.raisedButton {
public static var masksToBounds: Bool = true public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = .Radius1 public static var cornerRadius: MaterialRadius = .Radius1
public static var contentInsets: MaterialInsets = .Rectangle2 public static var contentInsets: MaterialInsets = .Rectangle2
public static var shape: MaterialShape? = nil public static var shape: MaterialShape = .None
// border // border
public static var borderWidth: MaterialBorder = .None public static var borderWidth: MaterialBorder = .None
...@@ -260,7 +262,7 @@ public extension MaterialTheme.fabButton { ...@@ -260,7 +262,7 @@ public extension MaterialTheme.fabButton {
public static var masksToBounds: Bool = true public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = .None public static var cornerRadius: MaterialRadius = .None
public static var contentInsets: MaterialInsets = .None public static var contentInsets: MaterialInsets = .None
public static var shape: MaterialShape? = .Circle public static var shape: MaterialShape = .Circle
// border // border
public static var borderWidth: MaterialBorder = .None public static var borderWidth: MaterialBorder = .None
......
...@@ -36,36 +36,36 @@ public class MaterialView : UIView { ...@@ -36,36 +36,36 @@ public class MaterialView : UIView {
/** /**
:name: contentsRect :name: contentsRect
*/ */
public var contentsRect: CGRect! { public var contentsRect: CGRect {
didSet { didSet {
visualLayer.contentsRect = nil == contentsRect ? CGRectMake(0, 0, 1, 1) : contentsRect! visualLayer.contentsRect = contentsRect
} }
} }
/** /**
:name: contentsCenter :name: contentsCenter
*/ */
public var contentsCenter: CGRect! { public var contentsCenter: CGRect {
didSet { didSet {
visualLayer.contentsCenter = nil == contentsCenter ? CGRectMake(0, 0, 1, 1) : contentsCenter! visualLayer.contentsCenter = contentsCenter
} }
} }
/** /**
:name: contentsScale :name: contentsScale
*/ */
public var contentsScale: CGFloat! { public var contentsScale: CGFloat {
didSet { didSet {
visualLayer.contentsScale = nil == contentsScale ? UIScreen.mainScreen().scale : contentsScale! visualLayer.contentsScale = contentsScale
} }
} }
/** /**
:name: contentsGravity :name: contentsGravity
*/ */
public var contentsGravity: MaterialGravity! { public var contentsGravity: MaterialGravity {
didSet { didSet {
visualLayer.contentsGravity = MaterialGravityToString(nil == contentsGravity ? .ResizeAspectFill : contentsGravity!) visualLayer.contentsGravity = MaterialGravityToString(contentsGravity)
} }
} }
...@@ -73,11 +73,8 @@ public class MaterialView : UIView { ...@@ -73,11 +73,8 @@ public class MaterialView : UIView {
:name: backgroundColor :name: backgroundColor
*/ */
public override var backgroundColor: UIColor? { public override var backgroundColor: UIColor? {
get { didSet {
return nil == layer.backgroundColor ? nil : UIColor(CGColor: layer.backgroundColor!) layer.backgroundColor = backgroundColor?.CGColor
}
set(value) {
layer.backgroundColor = value?.CGColor
} }
} }
...@@ -114,7 +111,7 @@ public class MaterialView : UIView { ...@@ -114,7 +111,7 @@ public class MaterialView : UIView {
} }
set(value) { set(value) {
layer.frame.size.width = value layer.frame.size.width = value
if nil != shape { if .None != shape {
layer.frame.size.height = value layer.frame.size.height = value
} }
} }
...@@ -129,7 +126,7 @@ public class MaterialView : UIView { ...@@ -129,7 +126,7 @@ public class MaterialView : UIView {
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
if nil != shape { if .None != shape {
layer.frame.size.width = value layer.frame.size.width = value
} }
} }
...@@ -138,56 +135,70 @@ public class MaterialView : UIView { ...@@ -138,56 +135,70 @@ public class MaterialView : UIView {
/** /**
:name: shadowColor :name: shadowColor
*/ */
public var shadowColor: UIColor! { public var shadowColor: UIColor? {
didSet { didSet {
layer.shadowColor = nil == shadowColor ? MaterialColor.clear.CGColor : shadowColor!.CGColor layer.shadowColor = shadowColor?.CGColor
} }
} }
/** /**
:name: shadowOffset :name: shadowOffset
*/ */
public var shadowOffset: CGSize! { public var shadowOffset: CGSize {
didSet { get {
layer.shadowOffset = nil == shadowOffset ? CGSizeMake(0, 0) : shadowOffset! return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
} }
} }
/** /**
:name: shadowOpacity :name: shadowOpacity
*/ */
public var shadowOpacity: Float! { public var shadowOpacity: Float {
didSet { get {
layer.shadowOpacity = nil == shadowOpacity ? 0 : shadowOpacity! return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
} }
} }
/** /**
:name: shadowRadius :name: shadowRadius
*/ */
public var shadowRadius: CGFloat! { public var shadowRadius: CGFloat {
didSet { get {
layer.shadowRadius = nil == shadowRadius ? 0 : shadowRadius! return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
} }
} }
/** /**
:name: masksToBounds :name: masksToBounds
*/ */
public var masksToBounds: Bool! { public var masksToBounds: Bool {
didSet { get {
visualLayer.masksToBounds = nil == masksToBounds ? false : masksToBounds! return visualLayer.masksToBounds
}
set(value) {
visualLayer.masksToBounds = value
} }
} }
/** /**
:name: cornerRadius :name: cornerRadius
*/ */
public var cornerRadius: MaterialRadius! { public var cornerRadius: MaterialRadius? {
didSet { didSet {
layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .None : cornerRadius!) if let v: MaterialRadius = cornerRadius {
if .Circle == shape { layer.cornerRadius = MaterialRadiusToValue(v)
shape = nil if .Circle == shape {
shape = .None
}
} }
} }
} }
...@@ -195,9 +206,9 @@ public class MaterialView : UIView { ...@@ -195,9 +206,9 @@ public class MaterialView : UIView {
/** /**
:name: shape :name: shape
*/ */
public var shape: MaterialShape? { public var shape: MaterialShape {
didSet { didSet {
if nil != shape { if .None != shape {
if width < height { if width < height {
layer.frame.size.width = height layer.frame.size.width = height
} else { } else {
...@@ -210,27 +221,27 @@ public class MaterialView : UIView { ...@@ -210,27 +221,27 @@ public class MaterialView : UIView {
/** /**
:name: borderWidth :name: borderWidth
*/ */
public var borderWidth: MaterialBorder! { public var borderWidth: MaterialBorder {
didSet { didSet {
layer.borderWidth = MaterialBorderToValue(nil == borderWidth ? .None : borderWidth!) layer.borderWidth = MaterialBorderToValue(borderWidth)
} }
} }
/** /**
:name: borderColor :name: borderColor
*/ */
public var borderColor: UIColor! { public var borderColor: UIColor? {
didSet { didSet {
layer.borderColor = nil == borderColor ? MaterialColor.clear.CGColor : borderColor!.CGColor layer.borderColor = borderColor?.CGColor
} }
} }
/** /**
:name: shadowDepth :name: shadowDepth
*/ */
public var shadowDepth: MaterialDepth! { public var shadowDepth: MaterialDepth {
didSet { didSet {
let value: MaterialDepthType = MaterialDepthToValue(nil == shadowDepth ? .None : shadowDepth!) let value: MaterialDepthType = MaterialDepthToValue(shadowDepth)
shadowOffset = value.offset shadowOffset = value.offset
shadowOpacity = value.opacity shadowOpacity = value.opacity
shadowRadius = value.radius shadowRadius = value.radius
...@@ -252,9 +263,12 @@ public class MaterialView : UIView { ...@@ -252,9 +263,12 @@ public class MaterialView : UIView {
/** /**
:name: zPosition :name: zPosition
*/ */
public var zPosition: CGFloat! { public var zPosition: CGFloat {
didSet { get {
layer.zPosition = zPosition return layer.zPosition
}
set(value) {
layer.zPosition = value
} }
} }
...@@ -262,6 +276,13 @@ public class MaterialView : UIView { ...@@ -262,6 +276,13 @@ public class MaterialView : UIView {
:name: init :name: init
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsRect = MaterialTheme.view.contentsRect
contentsCenter = MaterialTheme.view.contentsCenter
contentsScale = MaterialTheme.view.contentsScale
contentsGravity = MaterialTheme.view.contentsGravity
borderWidth = MaterialTheme.view.borderWidth
shadowDepth = .None
shape = .None
super.init(coder: aDecoder) super.init(coder: aDecoder)
} }
...@@ -269,6 +290,13 @@ public class MaterialView : UIView { ...@@ -269,6 +290,13 @@ public class MaterialView : UIView {
:name: init :name: init
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
contentsRect = MaterialTheme.view.contentsRect
contentsCenter = MaterialTheme.view.contentsCenter
contentsScale = MaterialTheme.view.contentsScale
contentsGravity = MaterialTheme.view.contentsGravity
borderWidth = MaterialTheme.view.borderWidth
shadowDepth = .None
shape = .None
super.init(frame: frame) super.init(frame: frame)
prepareView() prepareView()
} }
...@@ -367,16 +395,11 @@ public class MaterialView : UIView { ...@@ -367,16 +395,11 @@ public class MaterialView : UIView {
userInteractionEnabled = MaterialTheme.view.userInteractionEnabled userInteractionEnabled = MaterialTheme.view.userInteractionEnabled
backgroundColor = MaterialTheme.view.backgroundColor backgroundColor = MaterialTheme.view.backgroundColor
contentsRect = MaterialTheme.view.contentsRect
contentsCenter = MaterialTheme.view.contentsCenter
contentsScale = MaterialTheme.view.contentsScale
contentsGravity = MaterialTheme.view.contentsGravity
shadowDepth = MaterialTheme.view.shadowDepth shadowDepth = MaterialTheme.view.shadowDepth
shadowColor = MaterialTheme.view.shadowColor shadowColor = MaterialTheme.view.shadowColor
zPosition = MaterialTheme.view.zPosition zPosition = MaterialTheme.view.zPosition
masksToBounds = MaterialTheme.view.masksToBounds masksToBounds = MaterialTheme.view.masksToBounds
cornerRadius = MaterialTheme.view.cornerRadius cornerRadius = MaterialTheme.view.cornerRadius
borderWidth = MaterialTheme.view.borderWidth
borderColor = MaterialTheme.view.bordercolor borderColor = MaterialTheme.view.bordercolor
// visualLayer // visualLayer
......
...@@ -29,6 +29,25 @@ public class NavigationBarView : MaterialView { ...@@ -29,6 +29,25 @@ public class NavigationBarView : MaterialView {
} }
/** /**
:name: contentInsets
*/
public var contentInsets: MaterialInsets? {
didSet {
contentInsetsRef = nil == contentInsets ? nil : MaterialInsetsToValue(contentInsets!)
}
}
/**
:name: contentInsetsRef
*/
public var contentInsetsRef: MaterialInsetsType! {
didSet {
contentInsetsRef = nil == contentInsetsRef ? (top: 0, left: 0, bottom: 0, right: 0) : contentInsetsRef!
reloadView()
}
}
/**
:name: titleLabelInsets :name: titleLabelInsets
*/ */
public var titleLabelInsets: MaterialInsets? { public var titleLabelInsets: MaterialInsets? {
...@@ -52,9 +71,36 @@ public class NavigationBarView : MaterialView { ...@@ -52,9 +71,36 @@ public class NavigationBarView : MaterialView {
*/ */
public var titleLabel: UILabel? { public var titleLabel: UILabel? {
didSet { didSet {
if let v = titleLabel { titleLabel?.translatesAutoresizingMaskIntoConstraints = false
v.translatesAutoresizingMaskIntoConstraints = false reloadView()
} }
}
/**
:name: detailLabelInsets
*/
public var detailLabelInsets: MaterialInsets? {
didSet {
detailLabelInsetsRef = nil == detailLabelInsets ? nil : MaterialInsetsToValue(detailLabelInsets!)
}
}
/**
:name: detailLabelInsetsRef
*/
public var detailLabelInsetsRef: MaterialInsetsType! {
didSet {
detailLabelInsetsRef = nil == detailLabelInsetsRef ? (top: 0, left: 0, bottom: 0, right: 0) : detailLabelInsetsRef!
reloadView()
}
}
/**
:name: detailLabel
*/
public var detailLabel: UILabel? {
didSet {
detailLabel?.translatesAutoresizingMaskIntoConstraints = false
reloadView() reloadView()
} }
} }
...@@ -69,7 +115,7 @@ public class NavigationBarView : MaterialView { ...@@ -69,7 +115,7 @@ public class NavigationBarView : MaterialView {
} }
/** /**
:name: leftButtonsInsetsRef :name: leftButtonsInsetsRef
*/ */
public var leftButtonsInsetsRef: MaterialInsetsType! { public var leftButtonsInsetsRef: MaterialInsetsType! {
didSet { didSet {
...@@ -106,6 +152,7 @@ public class NavigationBarView : MaterialView { ...@@ -106,6 +152,7 @@ public class NavigationBarView : MaterialView {
*/ */
public var rightButtonsInsetsRef: MaterialInsetsType! { public var rightButtonsInsetsRef: MaterialInsetsType! {
didSet { didSet {
rightButtonsInsetsRef = nil == rightButtonsInsetsRef ? (top: 0, left: 0, bottom: 0, right: 0) : rightButtonsInsetsRef!
reloadView() reloadView()
} }
} }
...@@ -142,15 +189,15 @@ public class NavigationBarView : MaterialView { ...@@ -142,15 +189,15 @@ public class NavigationBarView : MaterialView {
:name: init :name: init
*/ */
public convenience init() { public convenience init() {
self.init(frame: CGRectMake(MaterialTheme.navigationBarView.x, MaterialTheme.navigationBarView.y, MaterialTheme.navigationBarView.width, MaterialTheme.navigationBarView.height)) self.init(frame: CGRectNull)
} }
/** /**
:name: init :name: init
*/ */
public convenience init?(titleLabel: UILabel? = nil, leftButtons: Array<MaterialButton>? = nil, rightButtons: Array<MaterialButton>? = nil) { public convenience init?(titleLabel: UILabel? = nil, detailLabel: UILabel? = nil, leftButtons: Array<MaterialButton>? = nil, rightButtons: Array<MaterialButton>? = nil) {
self.init(frame: CGRectMake(MaterialTheme.navigationBarView.x, MaterialTheme.navigationBarView.y, MaterialTheme.navigationBarView.width, MaterialTheme.navigationBarView.height)) self.init(frame: CGRectNull)
self.prepareProperties(titleLabel, leftButtons: leftButtons, rightButtons: rightButtons) prepareProperties(titleLabel, detailLabel: detailLabel, leftButtons: leftButtons, rightButtons: rightButtons)
} }
/** /**
...@@ -163,35 +210,68 @@ public class NavigationBarView : MaterialView { ...@@ -163,35 +210,68 @@ public class NavigationBarView : MaterialView {
v.removeFromSuperview() v.removeFromSuperview()
} }
var verticalFormat: String = "V:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var metrics: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
if nil != titleLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef!.top + titleLabelInsetsRef!.top
} else if nil != detailLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef!.top + detailLabelInsetsRef!.top
}
// title
if let v = titleLabel {
verticalFormat += "-[titleLabel]"
views["titleLabel"] = v
addSubview(v)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + titleLabelInsetsRef!.left, right: contentInsetsRef!.right + titleLabelInsetsRef!.right)
}
// detail
if let v = detailLabel {
if nil != titleLabel {
verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInsetsRef!.bottom + detailLabelInsetsRef!.top
}
verticalFormat += "-[detailLabel]"
views["detailLabel"] = v
addSubview(v)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + detailLabelInsetsRef!.left, right: contentInsetsRef!.right + detailLabelInsetsRef!.right)
}
// leftButtons // leftButtons
if let v = leftButtons { if let v = leftButtons {
if 0 < v.count { if 0 < v.count {
var h: String = "H:|" var h: String = "H:|"
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var i: Int = 0 var i: Int = 0
for b in v { for b in v {
let k: String = "b\(i++)" let k: String = "b\(i)"
d[k] = b d[k] = b
h += "-(left)-[\(k)]"
if 0 == i++ {
h += "-(left)-"
} else {
h += "-(left_right)-"
}
h += "[\(k)]"
addSubview(b) addSubview(b)
b.layer.zPosition = 2000 MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef!.bottom + leftButtonsInsetsRef!.bottom)
MaterialLayout.alignFromBottom(self, child: b, bottom: leftButtonsInsetsRef!.bottom)
} }
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : leftButtonsInsetsRef!.left], views: d)) addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : leftButtonsInsetsRef!.left, "left_right" : leftButtonsInsetsRef!.left + leftButtonsInsetsRef!.right], views: d))
} }
} }
// title
if let v = titleLabel {
addSubview(v)
v.layer.zPosition = 1500
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: titleLabelInsetsRef!.left, right: titleLabelInsetsRef!.right)
MaterialLayout.alignFromBottom(self, child: v, bottom: titleLabelInsetsRef!.bottom)
}
// rightButtons // rightButtons
if let v = rightButtons { if let v = rightButtons {
if 0 < v.count { if 0 < v.count {
...@@ -200,25 +280,52 @@ public class NavigationBarView : MaterialView { ...@@ -200,25 +280,52 @@ public class NavigationBarView : MaterialView {
var i: Int = 0 var i: Int = 0
for b in v { for b in v {
let k: String = "b\(i++)" let k: String = "b\(i)"
d[k] = b d[k] = b
h += "[\(k)]-(right)-"
h += "[\(k)]"
if 0 == i++ {
h += "-(right_left)-"
} else {
h += "-(right)-"
}
addSubview(b) addSubview(b)
b.layer.zPosition = 2000 MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef!.bottom + rightButtonsInsetsRef!.bottom)
MaterialLayout.alignFromBottom(self, child: b, bottom: rightButtonsInsetsRef!.bottom)
} }
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : rightButtonsInsetsRef!.right], views: d)) addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : rightButtonsInsetsRef!.right, "right_left" : rightButtonsInsetsRef!.right + rightButtonsInsetsRef!.left], views: d))
}
}
if nil != detailLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef!.bottom + detailLabelInsetsRef!.bottom
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInsetsRef!.bottom
}
} else if nil != titleLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef!.bottom + titleLabelInsetsRef!.bottom
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + titleLabelInsetsRef!.bottom
} }
} }
if 0 < views.count {
verticalFormat += "-(insetBottom)-|"
addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views))
}
} }
// //
// :name: prepareProperties // :name: prepareProperties
// //
internal func prepareProperties(titleLabel: UILabel?, leftButtons: Array<MaterialButton>?, rightButtons: Array<MaterialButton>?) { internal func prepareProperties(titleLabel: UILabel?, detailLabel: UILabel?, leftButtons: Array<MaterialButton>?, rightButtons: Array<MaterialButton>?) {
self.titleLabel = titleLabel self.titleLabel = titleLabel
self.detailLabel = detailLabel
self.leftButtons = leftButtons self.leftButtons = leftButtons
self.rightButtons = rightButtons self.rightButtons = rightButtons
} }
...@@ -231,7 +338,9 @@ public class NavigationBarView : MaterialView { ...@@ -231,7 +338,9 @@ public class NavigationBarView : MaterialView {
userInteractionEnabled = MaterialTheme.navigationBarView.userInteractionEnabled userInteractionEnabled = MaterialTheme.navigationBarView.userInteractionEnabled
backgroundColor = MaterialTheme.navigationBarView.backgroundColor backgroundColor = MaterialTheme.navigationBarView.backgroundColor
statusBarStyle = MaterialTheme.navigationBarView.statusBarStyle statusBarStyle = MaterialTheme.navigationBarView.statusBarStyle
contentInsetsRef = MaterialTheme.navigationBarView.contentInsetsRef
titleLabelInsetsRef = MaterialTheme.navigationBarView.titleLabelInsetsRef titleLabelInsetsRef = MaterialTheme.navigationBarView.titleLabelInsetsRef
detailLabelInsetsRef = MaterialTheme.navigationBarView.detailLabelInsetsRef
leftButtonsInsetsRef = MaterialTheme.navigationBarView.leftButtonsInsetsRef leftButtonsInsetsRef = MaterialTheme.navigationBarView.leftButtonsInsetsRef
rightButtonsInsetsRef = MaterialTheme.navigationBarView.rightButtonsInsetsRef rightButtonsInsetsRef = MaterialTheme.navigationBarView.rightButtonsInsetsRef
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>createMarkedFile</key>
<false/>
<key>sheetClusters</key>
<array>
<array>
<string>MaterialKitTests.swift</string>
</array>
</array>
</dict>
</plist>
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