Commit 35e5adc6 by Daniel Dahan

preparing for release 1.22.0

parent 789161bf
......@@ -60,7 +60,7 @@
965C17C71BC8279F00B1059A /* BasicCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 965C17C61BC8279F00B1059A /* BasicCollectionViewCell.swift */; settings = {ASSET_TAGS = (); }; };
965C17C81BC82FEF00B1059A /* MaterialLayer.swift in Headers */ = {isa = PBXBuildFile; fileRef = 65AD15E91BC05B3A0068AF9C /* MaterialLayer.swift */; settings = {ATTRIBUTES = (Public, ); }; };
965C17C91BC82FEF00B1059A /* MaterialTextLayer.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */; settings = {ATTRIBUTES = (Public, ); }; };
965C17CA1BC82FEF00B1059A /* CardView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* CardView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
965C17CA1BC82FEF00B1059A /* ImageCardView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* ImageCardView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
965C17CB1BC82FEF00B1059A /* MaterialCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 965C17C41BC8273D00B1059A /* MaterialCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; };
965C17CC1BC82FEF00B1059A /* BasicCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 965C17C61BC8279F00B1059A /* BasicCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9693BF861BCB0E0A0087054A /* Material+UIFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9693BF851BCB0E0A0087054A /* Material+UIFont.swift */; settings = {ASSET_TAGS = (); }; };
......@@ -70,9 +70,11 @@
9693BF8D1BCB35910087054A /* MaterialBasicAnimation.swift in Headers */ = {isa = PBXBuildFile; fileRef = 65D2BEC61BBED1E400800B7B /* MaterialBasicAnimation.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9693BF8E1BCB35910087054A /* MaterialKeyframeAnimation.swift in Headers */ = {isa = PBXBuildFile; fileRef = 65D2BEC81BBED1FA00800B7B /* MaterialKeyframeAnimation.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9693BF8F1BCB35910087054A /* MaterialTransitionAnimation.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9693BF961BCCCB520087054A /* BasicCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9693BF951BCCCB520087054A /* BasicCardView.swift */; settings = {ASSET_TAGS = (); }; };
9693BF971BCCCCB30087054A /* BasicCardView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9693BF951BCCCB520087054A /* BasicCardView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9699879C1BC5FE49006D678E /* MaterialTextLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */; settings = {ASSET_TAGS = (); }; };
96C4FABE1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */; settings = {ASSET_TAGS = (); }; };
96D26BFD1BC23649006478BD /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* CardView.swift */; settings = {ASSET_TAGS = (); }; };
96D26BFD1BC23649006478BD /* ImageCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* ImageCardView.swift */; settings = {ASSET_TAGS = (); }; };
9A94D0FA1B895EA500F586A5 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 963832631B88E5BF0015F710 /* LICENSE */; };
9A94D0FB1B895EA500F586A5 /* Roboto-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38591B8956E300FE6B2D /* Roboto-Regular.ttf */; };
9A94D0FC1B895EA500F586A5 /* Roboto-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38571B8956CF00FE6B2D /* Roboto-Medium.ttf */; };
......@@ -126,9 +128,10 @@
965C17C61BC8279F00B1059A /* BasicCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionViewCell.swift; sourceTree = "<group>"; };
9693BF851BCB0E0A0087054A /* Material+UIFont.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIFont.swift"; sourceTree = "<group>"; };
9693BF891BCB35520087054A /* SideNavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideNavigationViewController.swift; sourceTree = "<group>"; };
9693BF951BCCCB520087054A /* BasicCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCardView.swift; sourceTree = "<group>"; };
9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTextLayer.swift; sourceTree = "<group>"; };
96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTransitionAnimation.swift; sourceTree = "<group>"; };
96D26BFC1BC23649006478BD /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; };
96D26BFC1BC23649006478BD /* ImageCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCardView.swift; sourceTree = "<group>"; };
9AAC38551B8956C500FE6B2D /* Roboto-Light.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Light.ttf"; sourceTree = "<group>"; };
9AAC38571B8956CF00FE6B2D /* Roboto-Medium.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Medium.ttf"; sourceTree = "<group>"; };
9AAC38591B8956E300FE6B2D /* Roboto-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Regular.ttf"; sourceTree = "<group>"; };
......@@ -289,7 +292,8 @@
964B17D71BBB38E2002A9CA0 /* Card */ = {
isa = PBXGroup;
children = (
96D26BFC1BC23649006478BD /* CardView.swift */,
9693BF951BCCCB520087054A /* BasicCardView.swift */,
96D26BFC1BC23649006478BD /* ImageCardView.swift */,
);
name = Card;
sourceTree = "<group>";
......@@ -375,7 +379,8 @@
964B17D61BBB31C2002A9CA0 /* MaterialLayout.swift in Headers */,
965C17C81BC82FEF00B1059A /* MaterialLayer.swift in Headers */,
965C17C91BC82FEF00B1059A /* MaterialTextLayer.swift in Headers */,
965C17CA1BC82FEF00B1059A /* CardView.swift in Headers */,
9693BF971BCCCCB30087054A /* BasicCardView.swift in Headers */,
965C17CA1BC82FEF00B1059A /* ImageCardView.swift in Headers */,
965C17CB1BC82FEF00B1059A /* MaterialCollectionViewCell.swift in Headers */,
965C17CC1BC82FEF00B1059A /* BasicCollectionViewCell.swift in Headers */,
9693BF8B1BCB35910087054A /* Material+UIFont.swift in Headers */,
......@@ -495,7 +500,8 @@
65BDD16C1BB88D1A006F7F2B /* MaterialShape.swift in Sources */,
65AD15EA1BC05B3A0068AF9C /* MaterialLayer.swift in Sources */,
65BDD1521BB6EE7C006F7F2B /* RobotoFont.swift in Sources */,
96D26BFD1BC23649006478BD /* CardView.swift in Sources */,
9693BF961BCCCB520087054A /* BasicCardView.swift in Sources */,
96D26BFD1BC23649006478BD /* ImageCardView.swift in Sources */,
65BDD1591BB6FE3E006F7F2B /* FlatButton.swift in Sources */,
65BDD1791BB99C0F006F7F2B /* RaisedButton.swift in Sources */,
964B17B41BBA447F002A9CA0 /* MaterialLayout.swift in Sources */,
......
......@@ -8,15 +8,15 @@ MaterialKit is on CocoaPods under the name [MK](https://cocoapods.org/?q=MK).
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.
![MKPreview](http://www.materialkit.io/github/img1.gif)
![MKPreview](http://www.materialkit.io/github/vid1.gif)
```swift
let v: MaterialView = MaterialView(frame: CGRectMake(87.5, 87.5, 200, 200))
let v: MaterialView = MaterialView(frame: CGRectMake(107, 107, 200, 200))
v.shape = .Circle
v.shadowDepth = .Depth3
v.borderWidth = .Border4
v.borderColor = MaterialColor.blue.accent3
v.image = UIImage(named: "img1")
v.borderColor = MaterialColor.blue.accent4
v.image = UIImage(named: "img2")
// Add to UIViewController.
view.addSubview(v)
......@@ -26,10 +26,10 @@ view.addSubview(v)
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.
![MKPreview](http://www.materialkit.io/github/img2.gif)
![MKPreview](http://www.materialkit.io/github/vid2.gif)
```swift
let v: MaterialPulseView = MaterialPulseView(frame: CGRectMake(87.5, 87.5, 200, 200))
let v: MaterialPulseView = MaterialPulseView(frame: CGRectMake(107, 107, 200, 200))
v.shape = .Square
v.shadowDepth = .Depth3
v.cornerRadius = .Radius3
......@@ -43,10 +43,10 @@ view.addSubview(v)
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.
![MKPreview](http://www.materialkit.io/github/img3.gif)
![MKPreview](http://www.materialkit.io/github/vid3.gif)
```swift
let v: FlatButton = FlatButton(frame: CGRectMake(100, 100, 200, 64))
let v: FlatButton = FlatButton(frame: CGRectMake(107, 107, 200, 200))
v.setTitle("Flat", forState: .Normal)
v.titleLabel!.font = RobotoFont.mediumWithSize(32)
......@@ -58,10 +58,10 @@ view.addSubview(v)
A RaisedButton is sure to get attention. Take a look at the following code sample.
![MKPreview](http://www.materialkit.io/github/img4.gif)
![MKPreview](http://www.materialkit.io/github/vid4.gif)
```swift
let v: RaisedButton = RaisedButton(frame: CGRectMake(100, 100, 200, 64))
let v: RaisedButton = RaisedButton(frame: CGRectMake(107, 107, 200, 200))
v.setTitle("Raised", forState: .Normal)
v.titleLabel!.font = RobotoFont.mediumWithSize(32)
......@@ -73,10 +73,10 @@ view.addSubview(v)
A FabButton is essential to Material Design's overall look. I leave this example as simple as possible to showcase its beauty.
![MKPreview](http://www.materialkit.io/github/img5.gif)
![MKPreview](http://www.materialkit.io/github/vid5.gif)
```swift
let v: FabButton = FabButton(frame: CGRectMake(100, 100, 64, 64))
let v: FabButton = FabButton(frame: CGRectMake(175, 175, 64, 64))
v.setImage(UIImage(named: "ic_create_white"), forState: .Normal)
v.setImage(UIImage(named: "ic_create_white"), forState: .Highlighted)
......@@ -88,14 +88,13 @@ view.addSubview(v)
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.
![MKPreview](http://www.materialkit.io/github/img6.gif)
![MKPreview](http://www.materialkit.io/github/vid6.gif)
```swift
let v: NavigationBarView = NavigationBarView(titleLabel: MaterialLabel())!
v.backgroundColor = MaterialColor.blue.accent3
v.statusBarStyle = .LightContent
v.titleLabel = MaterialLabel()
v.titleLabel!.text = "Title"
v.titleLabel!.textAlignment = .Center
v.titleLabel!.textColor = MaterialColor.white
......@@ -143,7 +142,7 @@ view.addSubview(v)
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.
![MKPreview](http://www.materialkit.io/github/img7.gif)
![MKPreview](http://www.materialkit.io/github/vid7.gif)
```swift
let v: BasicCardView = BasicCardView(titleLabel: UILabel(), detailLabel: UILabel())!
......@@ -151,11 +150,10 @@ v.backgroundColor = MaterialColor.blueGrey.darken1
v.dividerColor = MaterialColor.blueGrey.base
v.titleLabel!.textColor = MaterialColor.white
v.titleLabel!.font = RobotoFont.regularWithSize(18)
v.titleLabel!.font = RobotoFont.regularWithSize(24)
v.titleLabel!.text = "Card Title"
v.detailLabel!.textColor = MaterialColor.white
v.detailLabel!.font = RobotoFont.regularWithSize(14)
v.detailLabel!.lineBreakMode = .ByWordWrapping
v.detailLabel!.numberOfLines = 0
v.detailLabel!.text = "I am a very simple card. I am good at containing small bits of information. I am convenient because I require little code to use effectively."
......@@ -197,23 +195,28 @@ 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.
![MKPreview](http://www.materialkit.io/github/img8.gif)
![MKPreview](http://www.materialkit.io/github/vid8.gif)
```swift
let v: BasicCardView = BasicCardView(titleLabel: MaterialLabel(), detailLabel: MaterialLabel())!
let v: BasicCardView = BasicCardView(image: UIImage(named: "img2"), titleLabel: MaterialLabel(), detailLabel: MaterialLabel())!
v.spotlight = true
v.image = UIImage(named: "img4")
v.divider = false
v.titleLabel!.textColor = MaterialColor.white
v.titleLabel!.font = RobotoFont.regularWithSize(18)
v.titleLabel!.font = RobotoFont.regularWithSize(24)
v.titleLabel!.text = "Card Title"
v.detailLabel!.textColor = MaterialColor.white
v.detailLabel!.font = RobotoFont.regularWithSize(14)
v.detailLabel!.lineBreakMode = .ByWordWrapping
v.detailLabel!.numberOfLines = 0
v.detailLabel!.text = "I am a very simple card. I am good at containing small bits of information. I am convenient because I require little code to use effectively."
let b1: FlatButton = FlatButton()
b1.setImage(UIImage(named: "ic_star_white"), forState: .Normal)
b1.setImage(UIImage(named: "ic_star_white"), forState: .Highlighted)
b1.pulseColor = MaterialColor.white
v.rightButtons = [b1]
// Add to UIViewController
view.addSubview(v)
......@@ -226,10 +229,10 @@ MaterialLayout.alignFromTop(view, child: v, top: 100)
An ImageCardView is a great way to enclose many components into a single and presentable layout. Below is an example of setting one up.
![MKPreview](http://www.materialkit.io/github/img10.gif)
![MKPreview](http://www.materialkit.io/github/vid9.gif)
```swift
let v: ImageCardView = ImageCardView(image: UIImage(named: "img4"))!
let v: ImageCardView = ImageCardView(image: UIImage(named: "img2"))!
v.pulseColor = MaterialColor.blueGrey.lighten4
v.pulseFill = true
......@@ -237,10 +240,8 @@ v.titleLabel = MaterialLabel()
v.titleLabel!.textColor = MaterialColor.white
v.titleLabel!.font = RobotoFont.regularWithSize(24)
v.titleLabel!.text = "Card Title"
v.titleLabelInsetsRef!.top = 136
v.detailLabel = MaterialLabel()
v.detailLabel!.font = RobotoFont.regularWithSize(14)
v.detailLabel!.lineBreakMode = .ByWordWrapping
v.detailLabel!.numberOfLines = 0
v.detailLabel!.text = "I am a very simple card. I am good at containing small bits of information. I am convenient because I require little code to use effectively."
......@@ -271,15 +272,16 @@ MaterialLayout.alignFromTop(view, child: v, top: 100)
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.
![MKPreview](http://www.materialkit.io/github/img9.gif)
![MKPreview](http://www.materialkit.io/github/vid10.gif)
```swift
let v: MaterialPulseView = MaterialPulseView(frame: CGRectMake(50, 50, 200, 200))
let v: MaterialPulseView = MaterialPulseView(frame: CGRectMake(107, 107, 200, 200))
v.spotlight = true
v.shape = .Circle
v.shadowDepth = .Depth2
v.borderWidth = .Border1
v.backgroundColor = MaterialColor.blue.accent3
v.shadowDepth = .Depth3
v.borderWidth = .Border5
v.borderColor = MaterialColor.blue.accent4
v.backgroundColor = MaterialColor.amber.base
// Add to UIViewController.
view.addSubview(v)
......@@ -287,7 +289,7 @@ view.addSubview(v)
// Play animation group.
v.animation(MaterialAnimation.animationGroup([
MaterialAnimation.rotation(3),
MaterialAnimation.position(CGPointMake(225, 400)),
MaterialAnimation.position(CGPointMake(207, 400)),
MaterialAnimation.cornerRadius(30),
MaterialAnimation.backgroundColor(MaterialColor.red.darken1)
], duration: 1))
......
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
public class BasicCardView : MaterialPulseView {
//
// :name: dividerLayer
//
internal var dividerLayer: CAShapeLayer?
//
// :name: dividerColor
//
public var dividerColor: UIColor? {
didSet {
dividerLayer?.backgroundColor = dividerColor?.CGColor
}
}
/**
:name: divider
*/
public var divider: Bool = MaterialTheme.basicCardView.divider {
didSet {
reloadView()
}
}
/**
:name: dividerInsets
*/
public var dividerInsets: MaterialInsets? {
didSet {
dividerInsetsRef = nil == dividerInsets ? nil : MaterialInsetsToValue(dividerInsets!)
}
}
/**
:name: dividerInsetsRef
*/
public var dividerInsetsRef: MaterialInsetsType! {
didSet {
dividerInsetsRef = nil == dividerInsetsRef ? MaterialInsetsToValue(.None) : dividerInsetsRef!
reloadView()
}
}
/**
:name: contentInsets
*/
public var contentInsets: MaterialInsets? {
didSet {
contentInsetsRef = nil == contentInsets ? nil : MaterialInsetsToValue(contentInsets!)
}
}
/**
:name: contentInsetsRef
*/
public var contentInsetsRef: MaterialInsetsType! {
didSet {
contentInsetsRef = nil == contentInsetsRef ? MaterialInsetsToValue(.None) : contentInsetsRef!
reloadView()
}
}
/**
:name: titleLabelInsets
*/
public var titleLabelInsets: MaterialInsets? {
didSet {
titleLabelInsetsRef = nil == titleLabelInsets ? nil : MaterialInsetsToValue(titleLabelInsets!)
}
}
/**
:name: titleLabelInsetsRef
*/
public var titleLabelInsetsRef: MaterialInsetsType! {
didSet {
titleLabelInsetsRef = nil == titleLabelInsetsRef ? MaterialInsetsToValue(.None) : titleLabelInsetsRef!
reloadView()
}
}
/**
:name: titleLabel
*/
public var titleLabel: UILabel? {
didSet {
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 ? MaterialInsetsToValue(.None) : detailLabelInsetsRef!
reloadView()
}
}
/**
:name: detailLabel
*/
public var detailLabel: UILabel? {
didSet {
detailLabel?.translatesAutoresizingMaskIntoConstraints = false
reloadView()
}
}
/**
:name: leftButtonsInsets
*/
public var leftButtonsInsets: MaterialInsets? {
didSet {
leftButtonsInsetsRef = nil == leftButtonsInsets ? nil : MaterialInsetsToValue(leftButtonsInsets!)
}
}
/**
:name: leftButtonsInsetsRef
*/
public var leftButtonsInsetsRef: MaterialInsetsType! {
didSet {
leftButtonsInsetsRef = nil == leftButtonsInsetsRef ? MaterialInsetsToValue(.None) : leftButtonsInsetsRef!
reloadView()
}
}
/**
:name: leftButtons
*/
public var leftButtons: Array<UIButton>? {
didSet {
if let v = leftButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView()
}
}
/**
:name: rightButtonsInsets
*/
public var rightButtonsInsets: MaterialInsets? {
didSet {
rightButtonsInsetsRef = nil == rightButtonsInsets ? nil : MaterialInsetsToValue(rightButtonsInsets!)
}
}
/**
:name: rightButtonsInsetsRef
*/
public var rightButtonsInsetsRef: MaterialInsetsType! {
didSet {
rightButtonsInsetsRef = nil == rightButtonsInsetsRef ? MaterialInsetsToValue(.None) : rightButtonsInsetsRef!
reloadView()
}
}
/**
:name: rightButtons
*/
public var rightButtons: Array<UIButton>? {
didSet {
if let v = rightButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView()
}
}
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
/**
:name: init
*/
public override init(frame: CGRect) {
super.init(frame: frame)
}
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRectNull)
}
/**
:name: init
*/
public convenience init?(image: UIImage? = nil, titleLabel: UILabel? = nil, detailLabel: UILabel? = nil, leftButtons: Array<UIButton>? = nil, rightButtons: Array<UIButton>? = nil) {
self.init(frame: CGRectNull)
prepareProperties(image, titleLabel: titleLabel, detailLabel: detailLabel, leftButtons: leftButtons, rightButtons: rightButtons)
}
/**
:name: layoutSublayersOfLayer
*/
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
if divider {
var y: CGFloat = contentInsetsRef!.bottom + dividerInsetsRef!.bottom
if 0 < leftButtons?.count {
y += leftButtonsInsetsRef!.top + leftButtonsInsetsRef!.bottom + leftButtons![0].frame.size.height
} else if 0 < rightButtons?.count {
y += rightButtonsInsetsRef!.top + rightButtonsInsetsRef!.bottom + rightButtons![0].frame.size.height
}
if 0 < y {
prepareDivider(bounds.size.height - y - 0.5, width: bounds.size.width)
}
} else {
dividerLayer?.removeFromSuperlayer()
dividerLayer = nil
}
}
}
/**
:name: prepareView
*/
public override func prepareView() {
super.prepareView()
userInteractionEnabled = MaterialTheme.basicCardView.userInteractionEnabled
backgroundColor = MaterialTheme.basicCardView.backgroundColor
pulseColor = MaterialTheme.basicCardView.pulseColor
contentInsetsRef = MaterialTheme.basicCardView.contentInsetsRef
titleLabelInsetsRef = MaterialTheme.basicCardView.titleLabelInsetsRef
detailLabelInsetsRef = MaterialTheme.basicCardView.detailLabelInsetsRef
leftButtonsInsetsRef = MaterialTheme.basicCardView.leftButtonsInsetsRef
rightButtonsInsetsRef = MaterialTheme.basicCardView.rightButtonsInsetsRef
dividerInsetsRef = MaterialTheme.basicCardView.dividerInsetsRef
contentsRect = MaterialTheme.basicCardView.contentsRect
contentsCenter = MaterialTheme.basicCardView.contentsCenter
contentsScale = MaterialTheme.basicCardView.contentsScale
contentsGravity = MaterialTheme.basicCardView.contentsGravity
shadowDepth = MaterialTheme.basicCardView.shadowDepth
shadowColor = MaterialTheme.basicCardView.shadowColor
zPosition = MaterialTheme.basicCardView.zPosition
borderWidth = MaterialTheme.basicCardView.borderWidth
borderColor = MaterialTheme.basicCardView.bordercolor
dividerColor = MaterialTheme.basicCardView.dividerColor
}
/**
:name: reloadView
*/
public func reloadView() {
// clear constraints so new ones do not conflict
removeConstraints(constraints)
for v in subviews {
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 {
addSubview(v)
verticalFormat += "-[titleLabel]"
views["titleLabel"] = v
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + titleLabelInsetsRef!.left, right: contentInsetsRef!.right + titleLabelInsetsRef!.right)
}
// detail
if let v = detailLabel {
addSubview(v)
if nil == titleLabel {
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + detailLabelInsetsRef!.top
} else {
verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInsetsRef!.bottom + detailLabelInsetsRef!.top
}
verticalFormat += "-[detailLabel]"
views["detailLabel"] = 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)"
d[k] = b
if 0 == i++ {
h += "-(left)-"
} else {
h += "-(left_right)-"
}
h += "[\(k)]"
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef!.bottom + leftButtonsInsetsRef!.bottom)
}
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : contentInsetsRef!.left + leftButtonsInsetsRef!.left, "left_right" : leftButtonsInsetsRef!.left + leftButtonsInsetsRef!.right], views: d))
}
}
// rightButtons
if let v = rightButtons {
if 0 < v.count {
var h: String = "H:"
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var i: Int = v.count - 1
for b in v {
let k: String = "b\(i)"
d[k] = b
h += "[\(k)]"
if 0 == i-- {
h += "-(right)-"
} else {
h += "-(right_left)-"
}
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef!.bottom + rightButtonsInsetsRef!.bottom)
}
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : contentInsetsRef!.right + rightButtonsInsetsRef!.right, "right_left" : rightButtonsInsetsRef!.right + rightButtonsInsetsRef!.left], views: d))
}
}
if 0 < leftButtons?.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0]
metrics["insetC"] = leftButtonsInsetsRef!.top
metrics["insetBottom"] = contentInsetsRef!.bottom + leftButtonsInsetsRef!.bottom
} else if 0 < rightButtons?.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = rightButtons![0]
metrics["insetC"] = rightButtonsInsetsRef!.top
metrics["insetBottom"] = contentInsetsRef!.bottom + rightButtonsInsetsRef!.bottom
}
if nil != detailLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef!.bottom + detailLabelInsetsRef!.bottom + (divider ? dividerInsetsRef!.top + dividerInsetsRef!.bottom : 0)
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInsetsRef!.bottom + (divider ? dividerInsetsRef!.top + dividerInsetsRef!.bottom : 0)
}
} else if nil != titleLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef!.bottom + titleLabelInsetsRef!.bottom + (divider ? dividerInsetsRef!.top + dividerInsetsRef!.bottom : 0)
} else {
metrics["insetC"] = (metrics["insetTop"] as! CGFloat) + titleLabelInsetsRef!.bottom + (divider ? dividerInsetsRef!.top + dividerInsetsRef!.bottom : 0)
}
} else if nil != metrics["insetC"] {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInsetsRef!.top + (divider ? dividerInsetsRef!.top + dividerInsetsRef!.bottom : 0)
}
if 0 < views.count {
verticalFormat += "-(insetBottom)-|"
addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views))
}
}
//
// :name: prepareDivider
//
internal func prepareDivider(y: CGFloat, width: CGFloat) {
if nil == dividerLayer {
dividerLayer = CAShapeLayer()
dividerLayer!.zPosition = 0
layer.addSublayer(dividerLayer!)
}
dividerLayer?.backgroundColor = dividerColor?.CGColor
dividerLayer?.frame = CGRectMake(dividerInsetsRef!.left, y, width - dividerInsetsRef!.left - dividerInsetsRef!.right, 1)
}
//
// :name: prepareProperties
//
internal func prepareProperties(image: UIImage?, titleLabel: UILabel?, detailLabel: UILabel?, leftButtons: Array<UIButton>?, rightButtons: Array<UIButton>?) {
self.image = image
self.titleLabel = titleLabel
self.detailLabel = detailLabel
self.leftButtons = leftButtons
self.rightButtons = rightButtons
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@
import UIKit
public class CardView : MaterialPulseView {
public class ImageCardView : MaterialPulseView {
//
// :name: dividerLayer
//
......@@ -36,7 +36,7 @@ public class CardView : MaterialPulseView {
/**
:name: divider
*/
public var divider: Bool = MaterialTheme.cardView.divider {
public var divider: Bool = MaterialTheme.imageCardView.divider {
didSet {
reloadView()
}
......@@ -64,44 +64,48 @@ public class CardView : MaterialPulseView {
/**
:name: imageLayer
*/
public private(set) lazy var imageLayer: CAShapeLayer = CAShapeLayer()
public private(set) var imageLayer: CAShapeLayer?
/**
:name: image
*/
public override var image: UIImage? {
get {
return nil == imageLayer.contents ? nil : UIImage(CGImage: imageLayer.contents as! CGImage)
return nil == imageLayer?.contents ? nil : UIImage(CGImage: imageLayer?.contents as! CGImage)
}
set(value) {
if let v = value {
imageLayer.contents = v.CGImage
if 0 == maxImageSize {
if 0 == imageLayer.frame.size.height {
imageLayer.frame.size.height = v.size.height
}
prepareImageLayer()
imageLayer?.contents = v.CGImage
if 0 == maxImageHeight {
imageLayer?.frame.size.height = image!.size.height / contentsScale
} else {
imageLayer.frame.size.height = maxImageSize
let h: CGFloat = image!.size.height / contentsScale
imageLayer?.frame.size.height = maxImageHeight < h ? maxImageHeight : h
}
imageLayer.hidden = false
}
else {
imageLayer.contents = nil
imageLayer.frame = CGRectZero
imageLayer.hidden = true
imageLayer?.hidden = false
} else {
imageLayer?.contents = nil
imageLayer?.frame = CGRectZero
imageLayer?.hidden = true
imageLayer?.removeFromSuperlayer()
}
reloadView()
}
}
/**
:name: maxImageSize
:name: maxImageHeight
*/
public var maxImageSize: CGFloat = 0 {
public var maxImageHeight: CGFloat = 0 {
didSet {
if 0 < maxImageSize {
imageLayer.frame.size.height = maxImageSize
// imageLayer.contentsGravity = MaterialGravityToString(contentsGravity)
if 0 < maxImageHeight {
prepareImageLayer()
let h: CGFloat = image!.size.height / contentsScale
imageLayer?.frame.size.height = maxImageHeight < h ? maxImageHeight : h
} else {
maxImageHeight = 0
imageLayer?.frame.size.height = nil == image ? 0 : image!.size.height / contentsScale
}
reloadView()
}
......@@ -112,7 +116,8 @@ public class CardView : MaterialPulseView {
*/
public override var contentsRect: CGRect {
didSet {
imageLayer.contentsRect = contentsRect
prepareImageLayer()
imageLayer?.contentsRect = contentsRect
}
}
......@@ -121,7 +126,8 @@ public class CardView : MaterialPulseView {
*/
public override var contentsCenter: CGRect {
didSet {
imageLayer.contentsCenter = contentsCenter
prepareImageLayer()
imageLayer?.contentsCenter = contentsCenter
}
}
......@@ -130,7 +136,8 @@ public class CardView : MaterialPulseView {
*/
public override var contentsScale: CGFloat {
didSet {
imageLayer.contentsScale = contentsScale
prepareImageLayer()
imageLayer?.contentsScale = contentsScale
}
}
......@@ -139,7 +146,8 @@ public class CardView : MaterialPulseView {
*/
public override var contentsGravity: MaterialGravity {
didSet {
imageLayer.contentsGravity = MaterialGravityToString(contentsGravity)
prepareImageLayer()
imageLayer?.contentsGravity = MaterialGravityToString(contentsGravity)
}
}
......@@ -322,23 +330,29 @@ public class CardView : MaterialPulseView {
*/
public override func layoutSubviews() {
super.layoutSubviews()
// image
imageLayer.frame.size.width = bounds.size.width
// divider
if divider {
var y: CGFloat = contentInsetsRef!.bottom + dividerInsetsRef!.bottom
if 0 < leftButtons?.count {
y += leftButtonsInsetsRef!.top + leftButtonsInsetsRef!.bottom + leftButtons![0].frame.size.height
} else if 0 < rightButtons?.count {
y += rightButtonsInsetsRef!.top + rightButtonsInsetsRef!.bottom + rightButtons![0].frame.size.height
}
if 0 < y {
prepareDivider(bounds.size.height - y - 0.5, width: bounds.size.width)
imageLayer?.frame.size.width = bounds.size.width
}
/**
:name: layoutSublayersOfLayer
*/
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
if divider {
var y: CGFloat = contentInsetsRef!.bottom + dividerInsetsRef!.bottom
if 0 < leftButtons?.count {
y += leftButtonsInsetsRef!.top + leftButtonsInsetsRef!.bottom + leftButtons![0].frame.size.height
} else if 0 < rightButtons?.count {
y += rightButtonsInsetsRef!.top + rightButtonsInsetsRef!.bottom + rightButtons![0].frame.size.height
}
if 0 < y {
prepareDivider(bounds.size.height - y - 0.5, width: bounds.size.width)
}
} else {
dividerLayer?.removeFromSuperlayer()
dividerLayer = nil
}
} else {
dividerLayer?.removeFromSuperlayer()
dividerLayer = nil
}
}
......@@ -347,27 +361,27 @@ public class CardView : MaterialPulseView {
*/
public override func prepareView() {
super.prepareView()
userInteractionEnabled = MaterialTheme.cardView.userInteractionEnabled
backgroundColor = MaterialTheme.cardView.backgroundColor
pulseColor = MaterialTheme.cardView.pulseColor
userInteractionEnabled = MaterialTheme.imageCardView.userInteractionEnabled
backgroundColor = MaterialTheme.imageCardView.backgroundColor
pulseColor = MaterialTheme.imageCardView.pulseColor
contentInsetsRef = MaterialTheme.cardView.contentInsetsRef
titleLabelInsetsRef = MaterialTheme.cardView.titleLabelInsetsRef
detailLabelInsetsRef = MaterialTheme.cardView.detailLabelInsetsRef
leftButtonsInsetsRef = MaterialTheme.cardView.leftButtonsInsetsRef
rightButtonsInsetsRef = MaterialTheme.cardView.rightButtonsInsetsRef
dividerInsetsRef = MaterialTheme.cardView.dividerInsetsRef
contentInsetsRef = MaterialTheme.imageCardView.contentInsetsRef
titleLabelInsetsRef = MaterialTheme.imageCardView.titleLabelInsetsRef
detailLabelInsetsRef = MaterialTheme.imageCardView.detailLabelInsetsRef
leftButtonsInsetsRef = MaterialTheme.imageCardView.leftButtonsInsetsRef
rightButtonsInsetsRef = MaterialTheme.imageCardView.rightButtonsInsetsRef
dividerInsetsRef = MaterialTheme.imageCardView.dividerInsetsRef
contentsRect = MaterialTheme.cardView.contentsRect
contentsCenter = MaterialTheme.cardView.contentsCenter
contentsScale = MaterialTheme.cardView.contentsScale
contentsGravity = MaterialTheme.cardView.contentsGravity
shadowDepth = MaterialTheme.cardView.shadowDepth
shadowColor = MaterialTheme.cardView.shadowColor
zPosition = MaterialTheme.cardView.zPosition
borderWidth = MaterialTheme.cardView.borderWidth
borderColor = MaterialTheme.cardView.bordercolor
dividerColor = MaterialTheme.cardView.dividerColor
contentsRect = MaterialTheme.imageCardView.contentsRect
contentsCenter = MaterialTheme.imageCardView.contentsCenter
contentsScale = MaterialTheme.imageCardView.contentsScale
contentsGravity = MaterialTheme.imageCardView.contentsGravity
shadowDepth = MaterialTheme.imageCardView.shadowDepth
shadowColor = MaterialTheme.imageCardView.shadowColor
zPosition = MaterialTheme.imageCardView.zPosition
borderWidth = MaterialTheme.imageCardView.borderWidth
borderColor = MaterialTheme.imageCardView.bordercolor
dividerColor = MaterialTheme.imageCardView.dividerColor
}
/**
......@@ -384,9 +398,9 @@ public class CardView : MaterialPulseView {
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var metrics: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
if nil != imageLayer.contents {
if nil != imageLayer?.contents {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = imageLayer.frame.size.height
metrics["insetTop"] = imageLayer?.frame.size.height
} else if nil != titleLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef!.top + titleLabelInsetsRef!.top
......@@ -399,7 +413,7 @@ public class CardView : MaterialPulseView {
if let v = titleLabel {
addSubview(v)
if nil == imageLayer.contents {
if nil == imageLayer?.contents {
verticalFormat += "-[titleLabel]"
views["titleLabel"] = v
} else {
......@@ -412,7 +426,7 @@ public class CardView : MaterialPulseView {
if let v = detailLabel {
addSubview(v)
if nil == imageLayer.contents && nil != titleLabel {
if nil == imageLayer?.contents && nil != titleLabel {
verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInsetsRef!.bottom + detailLabelInsetsRef!.top
} else {
......@@ -480,7 +494,7 @@ public class CardView : MaterialPulseView {
}
}
if nil == imageLayer.contents {
if nil == imageLayer?.contents {
if 0 < leftButtons?.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0]
......@@ -542,7 +556,6 @@ public class CardView : MaterialPulseView {
if 0 < views.count {
verticalFormat += "-(insetBottom)-|"
print(verticalFormat)
addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views))
}
}
......@@ -551,9 +564,12 @@ public class CardView : MaterialPulseView {
// :name: prepareImageLayer
//
internal func prepareImageLayer() {
imageLayer.masksToBounds = true
imageLayer.zPosition = 0
visualLayer.addSublayer(imageLayer)
if nil == imageLayer {
imageLayer = CAShapeLayer()
imageLayer!.masksToBounds = true
imageLayer!.zPosition = -1
visualLayer.addSublayer(imageLayer!)
}
}
//
......
......@@ -21,7 +21,8 @@ import UIKit
public struct MaterialTheme {
public struct view {}
public struct pulseView {}
public struct cardView {}
public struct basicCardView {}
public struct imageCardView {}
public struct navigationBarView {}
public struct textLayer {}
public struct label {}
......@@ -84,8 +85,48 @@ public extension MaterialTheme.pulseView {
public static var zPosition: CGFloat = 0
}
// cardView
public extension MaterialTheme.cardView {
// basicCardView
public extension MaterialTheme.basicCardView {
// shadow
public static var shadowDepth: MaterialDepth = .Depth2
public static var shadowColor: UIColor = MaterialColor.black
// shape
public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var titleLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var detailLabelInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var leftButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.None)
public static var rightButtonsInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.None)
public static var dividerInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: 8, right: 0)
// border
public static var borderWidth: MaterialBorder = .None
public static var bordercolor: UIColor = MaterialColor.black
// color
public static var backgroundColor: UIColor = MaterialColor.white
public static var pulseColor: UIColor = MaterialColor.blueGrey.lighten4
public static var pulseColorOpacity: CGFloat = 0.25
// interaction
public static var userInteractionEnabled: Bool = true
// image
public static var contentsRect: CGRect = CGRectMake(0, 0, 1, 1)
public static var contentsCenter: CGRect = CGRectMake(0, 0, 1, 1)
public static var contentsScale: CGFloat = UIScreen.mainScreen().scale
public static var contentsGravity: MaterialGravity = .ResizeAspectFill
// position
public static var zPosition: CGFloat = 0
// divider
public static var divider: Bool = true
public static var dividerColor: UIColor = MaterialColor.blueGrey.lighten5
}
// imageCardView
public extension MaterialTheme.imageCardView {
// shadow
public static var shadowDepth: MaterialDepth = .Depth2
public static var shadowColor: UIColor = MaterialColor.black
......
......@@ -196,7 +196,7 @@ public class NavigationBarView : MaterialView {
:name: init
*/
public convenience init?(titleLabel: UILabel? = nil, detailLabel: UILabel? = nil, leftButtons: Array<UIButton>? = nil, rightButtons: Array<UIButton>? = nil) {
self.init(frame: CGRectNull)
self.init(frame: CGRectMake(MaterialTheme.navigationBarView.x, MaterialTheme.navigationBarView.y, MaterialTheme.navigationBarView.width, MaterialTheme.navigationBarView.height))
prepareProperties(titleLabel, detailLabel: detailLabel, leftButtons: leftButtons, rightButtons: rightButtons)
}
......
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