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 @@
### 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
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
let v: MaterialView = MaterialView(frame: CGRectMake(100, 100, 200, 200))
`let v: MaterialView = MaterialView(frame: CGRectMake(100, 100, 200, 200))
v.shape = .Circle
v.shadowDepth = .Depth2
v.borderWidth = .Border1
......@@ -20,15 +20,15 @@ v.image = UIImage(named: "focus")
// Add to UIViewController.
view.addSubview(v)
```
`
### 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.
![MaterialKitPreview](http://www.materialkit.io/github/img2.gif)
![MaterialKitPreview][image-2]
```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.cornerRadius = .Radius2
v.shadowDepth = .Depth2
......@@ -37,60 +37,60 @@ v.image = UIImage(named: "focus")
// Add to UIViewController.
view.addSubview(v)
```
`
### 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.
![MaterialKitPreview](http://www.materialkit.io/github/img3.gif)
![MaterialKitPreview][image-3]
```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.titleLabel!.font = RobotoFont.mediumWithSize(32)
// Add to UIViewController.
view.addSubview(v)
```
`
### Noticeable RaisedButton
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
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.titleLabel!.font = RobotoFont.mediumWithSize(32)
// Add to UIViewController.
view.addSubview(v)
```
`
### Actionable FabButton
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
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: .Highlighted)
`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: .Highlighted)
// Add to UIViewController.
view.addSubview(v)
```
`
### 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.
![MaterialKitPreview](http://www.materialkit.io/github/img6.gif)
![MaterialKitPreview][image-6]
```swift
let v: NavigationBarView = NavigationBarView(titleLabel: MaterialLabel())!
`let v: NavigationBarView = NavigationBarView(titleLabel: MaterialLabel())!
v.backgroundColor = MaterialColor.blue.accent3
v.statusBarStyle = .LightContent
......@@ -126,15 +126,15 @@ v.rightButtons = [b3, b4]
// Add to UIViewController.
view.addSubview(v)
```
`
### 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.
![MaterialKitPreview](http://www.materialkit.io/github/img7.gif)
![MaterialKitPreview][image-7]
```swift
let v: BasicCardView = BasicCardView(titleLabel: UILabel(), detailLabel: UILabel())!
`let v: BasicCardView = BasicCardView(titleLabel: UILabel(), detailLabel: UILabel())!
v.backgroundColor = MaterialColor.blueGrey.darken1
v.dividerColor = MaterialColor.blueGrey.base
......@@ -166,13 +166,13 @@ v.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParentHorizontallyWithInsets(view, child: v, left: 20, right: 20)
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.
![MaterialKitPreview](http://www.materialkit.io/github/img8.gif)
![MaterialKitPreview][image-8]
```swift
let v: BasicCardView = BasicCardView(titleLabel: UILabel(), detailLabel: UILabel())!
`let v: BasicCardView = BasicCardView(titleLabel: UILabel(), detailLabel: UILabel())!
v.image = UIImage(named: "forest")
......@@ -190,15 +190,15 @@ v.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParentHorizontallyWithInsets(view, child: v, left: 20, right: 20)
MaterialLayout.alignFromTop(view, child: v, top: 100)
```
`
### 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.
![MaterialKitPreview](http://www.materialkit.io/github/img9.gif)
![MaterialKitPreview][image-9]
```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.shadowDepth = .Depth2
v.borderWidth = .Border1
......@@ -209,19 +209,34 @@ view.addSubview(v)
// Play a group of animations.
v.animation(MaterialAnimation.animationGroup([
MaterialAnimation.rotation(3),
MaterialAnimation.position(CGPointMake(225, 400)),
MaterialAnimation.cornerRadius(30),
MaterialAnimation.backgroundColor(MaterialColor.red.darken1)
MaterialAnimation.rotation(3),
MaterialAnimation.position(CGPointMake(225, 400)),
MaterialAnimation.cornerRadius(30),
MaterialAnimation.backgroundColor(MaterialColor.red.darken1)
], duration: 1))
```
`### License
### License
[AGPLv3](http://choosealicense.com/licenses/agpl-3.0/)
[AGPLv3][2]
### Contributors
* [Daniel Dahan](https://github.com/danieldahan)
* [Adam Dahan](https://github.com/adamdahan)
* [Michael Reyder](https://github.com/michaelReyder)
* [Daniel Dahan][3]
* [Adam Dahan][4]
* [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 {
*/
public var titleLabel: UILabel? {
didSet {
if let v = titleLabel {
v.translatesAutoresizingMaskIntoConstraints = false
}
titleLabel?.translatesAutoresizingMaskIntoConstraints = false
reloadView()
}
}
......@@ -117,9 +115,7 @@ public class BasicCardView : MaterialPulseView {
*/
public var detailLabel: UILabel? {
didSet {
if let v = detailLabel {
v.translatesAutoresizingMaskIntoConstraints = false
}
detailLabel?.translatesAutoresizingMaskIntoConstraints = false
reloadView()
}
}
......@@ -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) {
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 {
views["titleLabel"] = v
addSubview(v)
v.layer.zPosition = 2000
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + titleLabelInsetsRef!.left, right: contentInsetsRef!.right + titleLabelInsetsRef!.right)
}
......@@ -284,7 +279,6 @@ public class BasicCardView : MaterialPulseView {
views["detailLabel"] = v
addSubview(v)
v.layer.zPosition = 2000
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + detailLabelInsetsRef!.left, right: contentInsetsRef!.right + detailLabelInsetsRef!.right)
}
......@@ -294,18 +288,24 @@ public class BasicCardView : MaterialPulseView {
var h: String = "H:|"
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var i: Int = 0
for b in v {
let k: String = "b\(i++)"
let k: String = "b\(i)"
d[k] = b
h += "-(left)-[\(k)]"
if 0 == i++ {
h += "-(left)-"
} else {
h += "-(left_right)-"
}
h += "[\(k)]"
addSubview(b)
b.layer.zPosition = 2000
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 {
var i: Int = 0
for b in v {
let k: String = "b\(i++)"
let k: String = "b\(i)"
d[k] = b
h += "[\(k)]-(right)-"
h += "[\(k)]"
if 0 == i++ {
h += "-(right_left)-"
} else {
h += "-(right)-"
}
addSubview(b)
b.layer.zPosition = 2000
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 {
dividerLayer = CAShapeLayer()
dividerLayer!.backgroundColor = dividerColor?.CGColor
dividerLayer!.frame = CGRectMake(0, y, width, 1)
dividerLayer!.zPosition = 900
dividerLayer!.zPosition = 0
layer.addSublayer(dividerLayer!)
}
}
......
......@@ -47,9 +47,8 @@ public class MaterialButton : UIButton {
/**
:name: pulseColorOpacity
*/
public var pulseColorOpacity: CGFloat! {
public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity {
didSet {
pulseColorOpacity = nil == pulseColorOpacity ? 0.25 : pulseColorOpacity!
preparePulseLayer()
}
}
......@@ -67,11 +66,8 @@ public class MaterialButton : UIButton {
:name: backgroundColor
*/
public override var backgroundColor: UIColor? {
get {
return nil == layer.backgroundColor ? nil : UIColor(CGColor: layer.backgroundColor!)
}
set(value) {
layer.backgroundColor = value?.CGColor
didSet {
layer.backgroundColor = backgroundColor?.CGColor
}
}
......@@ -108,7 +104,7 @@ public class MaterialButton : UIButton {
}
set(value) {
layer.frame.size.width = value
if nil != shape {
if .None != shape {
layer.frame.size.height = value
}
}
......@@ -123,7 +119,7 @@ public class MaterialButton : UIButton {
}
set(value) {
layer.frame.size.height = value
if nil != shape {
if .None != shape {
layer.frame.size.width = value
}
}
......@@ -132,56 +128,70 @@ public class MaterialButton : UIButton {
/**
:name: shadowColor
*/
public var shadowColor: UIColor! {
public var shadowColor: UIColor? {
didSet {
layer.shadowColor = nil == shadowColor ? MaterialColor.clear.CGColor : shadowColor!.CGColor
layer.shadowColor = shadowColor?.CGColor
}
}
/**
:name: shadowOffset
*/
public var shadowOffset: CGSize! {
didSet {
layer.shadowOffset = nil == shadowOffset ? CGSizeMake(0, 0) : shadowOffset!
public var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
}
}
/**
:name: shadowOpacity
*/
public var shadowOpacity: Float! {
didSet {
layer.shadowOpacity = nil == shadowOpacity ? 0 : shadowOpacity!
public var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
}
}
/**
:name: shadowRadius
*/
public var shadowRadius: CGFloat! {
didSet {
layer.shadowRadius = nil == shadowRadius ? 0 : shadowRadius!
public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
}
}
/**
:name: masksToBounds
*/
public var masksToBounds: Bool! {
didSet {
visualLayer.masksToBounds = nil == masksToBounds ? false : masksToBounds!
public var masksToBounds: Bool {
get {
return visualLayer.masksToBounds
}
set(value) {
visualLayer.masksToBounds = value
}
}
/**
:name: cornerRadius
*/
public var cornerRadius: MaterialRadius! {
public var cornerRadius: MaterialRadius? {
didSet {
layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .None : cornerRadius!)
if .Circle == shape {
shape = nil
if let v: MaterialRadius = cornerRadius {
layer.cornerRadius = MaterialRadiusToValue(v)
if .Circle == shape {
shape = .None
}
}
}
}
......@@ -189,9 +199,9 @@ public class MaterialButton : UIButton {
/**
:name: shape
*/
public var shape: MaterialShape? {
public var shape: MaterialShape {
didSet {
if nil != shape {
if .None != shape {
if width < height {
layer.frame.size.width = height
} else {
......@@ -204,27 +214,27 @@ public class MaterialButton : UIButton {
/**
:name: borderWidth
*/
public var borderWidth: MaterialBorder! {
public var borderWidth: MaterialBorder {
didSet {
layer.borderWidth = MaterialBorderToValue(nil == borderWidth ? .None : borderWidth!)
layer.borderWidth = MaterialBorderToValue(borderWidth)
}
}
/**
:name: borderColor
*/
public var borderColor: UIColor! {
public var borderColor: UIColor? {
didSet {
layer.borderColor = nil == borderColor ? MaterialColor.clear.CGColor : borderColor!.CGColor
layer.borderColor = borderColor?.CGColor
}
}
/**
:name: shadowDepth
*/
public var shadowDepth: MaterialDepth! {
public var shadowDepth: MaterialDepth {
didSet {
let value: MaterialDepthType = MaterialDepthToValue(nil == shadowDepth ? .None : shadowDepth!)
let value: MaterialDepthType = MaterialDepthToValue(shadowDepth)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
......@@ -246,18 +256,21 @@ public class MaterialButton : UIButton {
/**
:name: zPosition
*/
public var zPosition: CGFloat! {
didSet {
layer.zPosition = zPosition
public var zPosition: CGFloat {
get {
return layer.zPosition
}
set(value) {
layer.zPosition = value
}
}
/**
:name: contentInsets
*/
public var contentInsets: MaterialInsets! {
public var contentInsets: MaterialInsets {
didSet {
let value: MaterialInsetsType = MaterialInsetsToValue(nil == contentInsets ? .None : contentInsets)
let value: MaterialInsetsType = MaterialInsetsToValue(contentInsets)
contentEdgeInsets = UIEdgeInsetsMake(value.top, value.left, value.bottom, value.right)
}
}
......@@ -266,6 +279,10 @@ public class MaterialButton : UIButton {
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
borderWidth = .None
shadowDepth = .None
shape = .None
contentInsets = .None
super.init(coder: aDecoder)
}
......@@ -273,6 +290,10 @@ public class MaterialButton : UIButton {
:name: init
*/
public override init(frame: CGRect) {
borderWidth = .None
shadowDepth = .None
shape = .None
contentInsets = .None
super.init(frame: frame)
prepareView()
}
......@@ -373,7 +394,7 @@ public class MaterialButton : UIButton {
let s: CGFloat = (width < height ? height : width) / 2
let f: CGFloat = 3
let v: CGFloat = s / f
let d: CGFloat = pulseFill ? 5 * f : 2 * f
let d: CGFloat = pulseFill ? 5 * f : 2.5 * f
MaterialAnimation.animationDisabled({
self.pulseLayer.hidden = false
self.pulseLayer.bounds = CGRectMake(0, 0, v, v)
......@@ -434,7 +455,7 @@ public class MaterialButton : UIButton {
// visualLayer
visualLayer.zPosition = -1
layer.addSublayer(visualLayer)
// pulseLayer
pulseLayer.hidden = true
pulseLayer.zPosition = 1
......@@ -454,7 +475,7 @@ public class MaterialButton : UIButton {
// :name: preparePulseLayer
//
internal func preparePulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity!).CGColor
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
}
//
......
......@@ -26,10 +26,12 @@ public enum MaterialInsets {
case Square2
case Square3
case Square4
case Square5
case Rectangle1
case Rectangle2
case Rectangle3
case Rectangle4
case Rectangle5
}
/**
......@@ -47,6 +49,8 @@ public func MaterialInsetsToValue(inset: MaterialInsets) -> MaterialInsetsType {
return (top: 16, left: 16, bottom: 16, right: 16)
case .Square4:
return (top: 32, left: 32, bottom: 32, right: 32)
case .Square5:
return (top: 64, left: 64, bottom: 64, right: 64)
case .Rectangle1:
return (top: 2, left: 4, bottom: 2, right: 4)
case .Rectangle2:
......@@ -55,5 +59,7 @@ public func MaterialInsetsToValue(inset: MaterialInsets) -> MaterialInsetsType {
return (top: 8, left: 16, bottom: 8, right: 16)
case .Rectangle4:
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 {
/**
:name: pulseColorOpacity
*/
public var pulseColorOpacity: CGFloat! {
public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity {
didSet {
pulseColorOpacity = nil == pulseColorOpacity ? 0.25 : pulseColorOpacity!
preparePulseLayer()
}
}
......@@ -54,7 +53,6 @@ public class MaterialPulseView : MaterialView {
*/
public var pulseColor: UIColor? {
didSet {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity!).CGColor
preparePulseLayer()
}
}
......@@ -130,7 +128,6 @@ public class MaterialPulseView : MaterialView {
super.prepareView()
userInteractionEnabled = MaterialTheme.pulseView.userInteractionEnabled
backgroundColor = MaterialTheme.pulseView.backgroundColor
pulseColorOpacity = MaterialTheme.pulseView.pulseColorOpacity
pulseColor = MaterialTheme.pulseView.pulseColor
contentsRect = MaterialTheme.pulseView.contentsRect
......@@ -155,7 +152,7 @@ public class MaterialPulseView : MaterialView {
// :name: preparePulseLayer
//
internal func preparePulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity!).CGColor
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
}
//
......
......@@ -17,6 +17,7 @@
//
public enum MaterialShape {
case None
case Square
case Circle
}
......@@ -103,8 +103,8 @@ public extension MaterialTheme.basicCardView {
public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square3)
public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
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 rightButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: -8, right: 16)
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: 8)
// border
public static var borderWidth: MaterialBorder = .None
......@@ -147,9 +147,11 @@ public extension MaterialTheme.navigationBarView {
// shape
public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = .None
public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Rectangle3)
public static var leftButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var rightButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.None)
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
public static var borderWidth: MaterialBorder = .None
......@@ -195,7 +197,7 @@ public extension MaterialTheme.flatButton {
public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = .Radius1
public static var contentInsets: MaterialInsets = .Rectangle3
public static var shape: MaterialShape? = nil
public static var shape: MaterialShape = .None
// border
public static var borderWidth: MaterialBorder = .None
......@@ -227,7 +229,7 @@ public extension MaterialTheme.raisedButton {
public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = .Radius1
public static var contentInsets: MaterialInsets = .Rectangle2
public static var shape: MaterialShape? = nil
public static var shape: MaterialShape = .None
// border
public static var borderWidth: MaterialBorder = .None
......@@ -260,7 +262,7 @@ public extension MaterialTheme.fabButton {
public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = .None
public static var contentInsets: MaterialInsets = .None
public static var shape: MaterialShape? = .Circle
public static var shape: MaterialShape = .Circle
// border
public static var borderWidth: MaterialBorder = .None
......
......@@ -36,36 +36,36 @@ public class MaterialView : UIView {
/**
:name: contentsRect
*/
public var contentsRect: CGRect! {
public var contentsRect: CGRect {
didSet {
visualLayer.contentsRect = nil == contentsRect ? CGRectMake(0, 0, 1, 1) : contentsRect!
visualLayer.contentsRect = contentsRect
}
}
/**
:name: contentsCenter
*/
public var contentsCenter: CGRect! {
public var contentsCenter: CGRect {
didSet {
visualLayer.contentsCenter = nil == contentsCenter ? CGRectMake(0, 0, 1, 1) : contentsCenter!
visualLayer.contentsCenter = contentsCenter
}
}
/**
:name: contentsScale
*/
public var contentsScale: CGFloat! {
public var contentsScale: CGFloat {
didSet {
visualLayer.contentsScale = nil == contentsScale ? UIScreen.mainScreen().scale : contentsScale!
visualLayer.contentsScale = contentsScale
}
}
/**
:name: contentsGravity
*/
public var contentsGravity: MaterialGravity! {
public var contentsGravity: MaterialGravity {
didSet {
visualLayer.contentsGravity = MaterialGravityToString(nil == contentsGravity ? .ResizeAspectFill : contentsGravity!)
visualLayer.contentsGravity = MaterialGravityToString(contentsGravity)
}
}
......@@ -73,11 +73,8 @@ public class MaterialView : UIView {
:name: backgroundColor
*/
public override var backgroundColor: UIColor? {
get {
return nil == layer.backgroundColor ? nil : UIColor(CGColor: layer.backgroundColor!)
}
set(value) {
layer.backgroundColor = value?.CGColor
didSet {
layer.backgroundColor = backgroundColor?.CGColor
}
}
......@@ -114,7 +111,7 @@ public class MaterialView : UIView {
}
set(value) {
layer.frame.size.width = value
if nil != shape {
if .None != shape {
layer.frame.size.height = value
}
}
......@@ -129,7 +126,7 @@ public class MaterialView : UIView {
}
set(value) {
layer.frame.size.height = value
if nil != shape {
if .None != shape {
layer.frame.size.width = value
}
}
......@@ -138,56 +135,70 @@ public class MaterialView : UIView {
/**
:name: shadowColor
*/
public var shadowColor: UIColor! {
public var shadowColor: UIColor? {
didSet {
layer.shadowColor = nil == shadowColor ? MaterialColor.clear.CGColor : shadowColor!.CGColor
layer.shadowColor = shadowColor?.CGColor
}
}
/**
:name: shadowOffset
*/
public var shadowOffset: CGSize! {
didSet {
layer.shadowOffset = nil == shadowOffset ? CGSizeMake(0, 0) : shadowOffset!
public var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
}
}
/**
:name: shadowOpacity
*/
public var shadowOpacity: Float! {
didSet {
layer.shadowOpacity = nil == shadowOpacity ? 0 : shadowOpacity!
public var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
}
}
/**
:name: shadowRadius
*/
public var shadowRadius: CGFloat! {
didSet {
layer.shadowRadius = nil == shadowRadius ? 0 : shadowRadius!
public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
}
}
/**
:name: masksToBounds
*/
public var masksToBounds: Bool! {
didSet {
visualLayer.masksToBounds = nil == masksToBounds ? false : masksToBounds!
public var masksToBounds: Bool {
get {
return visualLayer.masksToBounds
}
set(value) {
visualLayer.masksToBounds = value
}
}
/**
:name: cornerRadius
*/
public var cornerRadius: MaterialRadius! {
public var cornerRadius: MaterialRadius? {
didSet {
layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .None : cornerRadius!)
if .Circle == shape {
shape = nil
if let v: MaterialRadius = cornerRadius {
layer.cornerRadius = MaterialRadiusToValue(v)
if .Circle == shape {
shape = .None
}
}
}
}
......@@ -195,9 +206,9 @@ public class MaterialView : UIView {
/**
:name: shape
*/
public var shape: MaterialShape? {
public var shape: MaterialShape {
didSet {
if nil != shape {
if .None != shape {
if width < height {
layer.frame.size.width = height
} else {
......@@ -210,27 +221,27 @@ public class MaterialView : UIView {
/**
:name: borderWidth
*/
public var borderWidth: MaterialBorder! {
public var borderWidth: MaterialBorder {
didSet {
layer.borderWidth = MaterialBorderToValue(nil == borderWidth ? .None : borderWidth!)
layer.borderWidth = MaterialBorderToValue(borderWidth)
}
}
/**
:name: borderColor
*/
public var borderColor: UIColor! {
public var borderColor: UIColor? {
didSet {
layer.borderColor = nil == borderColor ? MaterialColor.clear.CGColor : borderColor!.CGColor
layer.borderColor = borderColor?.CGColor
}
}
/**
:name: shadowDepth
*/
public var shadowDepth: MaterialDepth! {
public var shadowDepth: MaterialDepth {
didSet {
let value: MaterialDepthType = MaterialDepthToValue(nil == shadowDepth ? .None : shadowDepth!)
let value: MaterialDepthType = MaterialDepthToValue(shadowDepth)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
......@@ -252,9 +263,12 @@ public class MaterialView : UIView {
/**
:name: zPosition
*/
public var zPosition: CGFloat! {
didSet {
layer.zPosition = zPosition
public var zPosition: CGFloat {
get {
return layer.zPosition
}
set(value) {
layer.zPosition = value
}
}
......@@ -262,6 +276,13 @@ public class MaterialView : UIView {
:name: init
*/
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)
}
......@@ -269,6 +290,13 @@ public class MaterialView : UIView {
:name: init
*/
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)
prepareView()
}
......@@ -367,16 +395,11 @@ public class MaterialView : UIView {
userInteractionEnabled = MaterialTheme.view.userInteractionEnabled
backgroundColor = MaterialTheme.view.backgroundColor
contentsRect = MaterialTheme.view.contentsRect
contentsCenter = MaterialTheme.view.contentsCenter
contentsScale = MaterialTheme.view.contentsScale
contentsGravity = MaterialTheme.view.contentsGravity
shadowDepth = MaterialTheme.view.shadowDepth
shadowColor = MaterialTheme.view.shadowColor
zPosition = MaterialTheme.view.zPosition
masksToBounds = MaterialTheme.view.masksToBounds
cornerRadius = MaterialTheme.view.cornerRadius
borderWidth = MaterialTheme.view.borderWidth
borderColor = MaterialTheme.view.bordercolor
// visualLayer
......
......@@ -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
*/
public var titleLabelInsets: MaterialInsets? {
......@@ -52,9 +71,36 @@ public class NavigationBarView : MaterialView {
*/
public var titleLabel: UILabel? {
didSet {
if let v = titleLabel {
v.translatesAutoresizingMaskIntoConstraints = false
}
titleLabel?.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()
}
}
......@@ -69,7 +115,7 @@ public class NavigationBarView : MaterialView {
}
/**
:name: leftButtonsInsetsRef
:name: leftButtonsInsetsRef
*/
public var leftButtonsInsetsRef: MaterialInsetsType! {
didSet {
......@@ -106,6 +152,7 @@ public class NavigationBarView : MaterialView {
*/
public var rightButtonsInsetsRef: MaterialInsetsType! {
didSet {
rightButtonsInsetsRef = nil == rightButtonsInsetsRef ? (top: 0, left: 0, bottom: 0, right: 0) : rightButtonsInsetsRef!
reloadView()
}
}
......@@ -142,15 +189,15 @@ public class NavigationBarView : MaterialView {
:name: 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
*/
public convenience init?(titleLabel: 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.prepareProperties(titleLabel, leftButtons: leftButtons, rightButtons: rightButtons)
public convenience init?(titleLabel: UILabel? = nil, detailLabel: UILabel? = nil, leftButtons: Array<MaterialButton>? = nil, rightButtons: Array<MaterialButton>? = nil) {
self.init(frame: CGRectNull)
prepareProperties(titleLabel, detailLabel: detailLabel, leftButtons: leftButtons, rightButtons: rightButtons)
}
/**
......@@ -163,35 +210,68 @@ public class NavigationBarView : MaterialView {
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
if let v = leftButtons {
if 0 < v.count {
var h: String = "H:|"
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var i: Int = 0
for b in v {
let k: String = "b\(i++)"
let k: String = "b\(i)"
d[k] = b
h += "-(left)-[\(k)]"
if 0 == i++ {
h += "-(left)-"
} else {
h += "-(left_right)-"
}
h += "[\(k)]"
addSubview(b)
b.layer.zPosition = 2000
MaterialLayout.alignFromBottom(self, child: b, 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))
}
}
// 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
if let v = rightButtons {
if 0 < v.count {
......@@ -200,25 +280,52 @@ public class NavigationBarView : MaterialView {
var i: Int = 0
for b in v {
let k: String = "b\(i++)"
let k: String = "b\(i)"
d[k] = b
h += "[\(k)]-(right)-"
h += "[\(k)]"
if 0 == i++ {
h += "-(right_left)-"
} else {
h += "-(right)-"
}
addSubview(b)
b.layer.zPosition = 2000
MaterialLayout.alignFromBottom(self, child: b, 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))
}
}
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
//
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.detailLabel = detailLabel
self.leftButtons = leftButtons
self.rightButtons = rightButtons
}
......@@ -231,7 +338,9 @@ public class NavigationBarView : MaterialView {
userInteractionEnabled = MaterialTheme.navigationBarView.userInteractionEnabled
backgroundColor = MaterialTheme.navigationBarView.backgroundColor
statusBarStyle = MaterialTheme.navigationBarView.statusBarStyle
contentInsetsRef = MaterialTheme.navigationBarView.contentInsetsRef
titleLabelInsetsRef = MaterialTheme.navigationBarView.titleLabelInsetsRef
detailLabelInsetsRef = MaterialTheme.navigationBarView.detailLabelInsetsRef
leftButtonsInsetsRef = MaterialTheme.navigationBarView.leftButtonsInsetsRef
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