Commit f65afdde by Daniel Dahan

updated MaterialLayer documentation and MaterialButton internals

parent 710ad186
......@@ -99,7 +99,7 @@
location = "container:"
name = "MaterialButton">
<FileRef
location = "group:/Users/danieldahan/Dropbox/GraphKit/Technology/Repositories/MaterialKit/Examples/Storyboards/MaterialButton/MaterialButton.xcodeproj">
location = "group:Storyboards/MaterialButton/MaterialButton.xcodeproj">
</FileRef>
</Group>
<Group
......
......@@ -7,8 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
960B23541C3870A500E96216 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 960B23531C3870A500E96216 /* MaterialKit.framework */; };
960B23551C3870A500E96216 /* MaterialKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 960B23531C3870A500E96216 /* MaterialKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
967513CA1C136BB7009F455A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967513C91C136BB7009F455A /* AppDelegate.swift */; };
967513CC1C136BB7009F455A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967513CB1C136BB7009F455A /* ViewController.swift */; };
967513D11C136BB7009F455A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 967513D01C136BB7009F455A /* Assets.xcassets */; };
......@@ -22,7 +20,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
960B23551C3870A500E96216 /* MaterialKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -30,7 +27,6 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
960B23531C3870A500E96216 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MaterialKit.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-gdulktuccbcfwbdfadtpxkworhyc/Build/Products/Debug-iphoneos/MaterialKit.framework"; sourceTree = "<absolute>"; };
967513C61C136BB7009F455A /* CardView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CardView.app; sourceTree = BUILT_PRODUCTS_DIR; };
967513C91C136BB7009F455A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
967513CB1C136BB7009F455A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
......@@ -44,7 +40,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
960B23541C3870A500E96216 /* MaterialKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -54,7 +49,6 @@
967513BD1C136BB7009F455A = {
isa = PBXGroup;
children = (
960B23531C3870A500E96216 /* MaterialKit.framework */,
967513C81C136BB7009F455A /* CardView */,
967513C71C136BB7009F455A /* Products */,
);
......
......@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
9637EB0E1C387F08006D9677 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9637EB0D1C387F08006D9677 /* MaterialKit.framework */; };
9637EB0F1C387F08006D9677 /* MaterialKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9637EB0D1C387F08006D9677 /* MaterialKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
965E8E261C149B530035A270 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 965E8E251C149B530035A270 /* AppDelegate.swift */; };
965E8E281C149B530035A270 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 965E8E271C149B530035A270 /* ViewController.swift */; };
965E8E2D1C149B530035A270 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 965E8E2C1C149B530035A270 /* Assets.xcassets */; };
......@@ -20,6 +22,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
9637EB0F1C387F08006D9677 /* MaterialKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -27,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
9637EB0D1C387F08006D9677 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MaterialKit.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-gdulktuccbcfwbdfadtpxkworhyc/Build/Products/Debug-iphoneos/MaterialKit.framework"; sourceTree = "<absolute>"; };
965E8E221C149B530035A270 /* MaterialLayer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MaterialLayer.app; sourceTree = BUILT_PRODUCTS_DIR; };
965E8E251C149B530035A270 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
965E8E271C149B530035A270 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
......@@ -40,6 +44,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9637EB0E1C387F08006D9677 /* MaterialKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -49,6 +54,7 @@
965E8E191C149B530035A270 = {
isa = PBXGroup;
children = (
9637EB0D1C387F08006D9677 /* MaterialKit.framework */,
965E8E241C149B530035A270 /* MaterialLayer */,
965E8E231C149B530035A270 /* Products */,
);
......
......@@ -20,24 +20,16 @@ import UIKit
public class FabButton : MaterialButton {
/**
:name: prepareView
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public override func prepareView() {
super.prepareView()
setTitleColor(MaterialTheme.fabButton.titleLabelColorForNormalState, forState: .Normal)
titleLabel?.font = MaterialTheme.fabButton.titleLabelFont
userInteractionEnabled = MaterialTheme.fabButton.userInteractionEnabled
backgroundColor = MaterialTheme.fabButton.backgroundColor
pulseColorOpacity = MaterialTheme.fabButton.pulseColorOpacity
pulseColor = MaterialTheme.fabButton.pulseColor
depth = MaterialTheme.fabButton.depth
shadowColor = MaterialTheme.fabButton.shadowColor
zPosition = MaterialTheme.fabButton.zPosition
borderWidth = MaterialTheme.fabButton.borderWidth
borderColor = MaterialTheme.fabButton.bordercolor
contentInsets = MaterialTheme.fabButton.contentInsets
shape = MaterialTheme.fabButton.shape
backgroundColor = MaterialColor.red.darken1
depth = .Depth2
shape = .Circle
}
}
\ No newline at end of file
......@@ -20,25 +20,17 @@ import UIKit
public class FlatButton : MaterialButton {
/**
:name: prepareView
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public override func prepareView() {
super.prepareView()
setTitleColor(MaterialTheme.flatButton.titleLabelColorForNormalState, forState: .Normal)
titleLabel?.font = MaterialTheme.flatButton.titleLabelFont
userInteractionEnabled = MaterialTheme.flatButton.userInteractionEnabled
backgroundColor = MaterialTheme.flatButton.backgroundColor
pulseColorOpacity = MaterialTheme.flatButton.pulseColorOpacity
pulseColor = MaterialTheme.flatButton.pulseColor
depth = MaterialTheme.flatButton.depth
shadowColor = MaterialTheme.flatButton.shadowColor
zPosition = MaterialTheme.flatButton.zPosition
cornerRadius = MaterialTheme.flatButton.cornerRadius
borderWidth = MaterialTheme.flatButton.borderWidth
borderColor = MaterialTheme.flatButton.bordercolor
contentInsets = MaterialTheme.flatButton.contentInsets
shape = MaterialTheme.flatButton.shape
setTitleColor(MaterialColor.blue.accent3, forState: .Normal)
pulseColor = MaterialColor.blue.accent3
cornerRadius = .Radius1
contentInsets = .WideRectangle3
}
}
\ No newline at end of file
......@@ -21,28 +21,25 @@ import UIKit
@objc(MaterialButton)
public class MaterialButton : UIButton {
/**
:name: visualLayer
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
allows the dropshadow effect on the backing layer, while clipping
the image to a desired shape within the visualLayer.
*/
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
/**
:name: pulseLayer
*/
/// A CAShapeLayer used in the pulse animation.
public private(set) lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
/**
:name: delegate
A base delegate reference used when subclassing MaterialView.
*/
public weak var delegate: MaterialDelegate?
/**
:name: pulseScale
*/
/// Sets whether the scaling animation should be used.
public lazy var pulseScale: Bool = true
/**
:name: spotlight
*/
/// Enables and disables the spotlight effect.
public var spotlight: Bool = false {
didSet {
if spotlight {
......@@ -52,7 +49,8 @@ public class MaterialButton : UIButton {
}
/**
:name: pulseFill
Determines if the pulse animation should fill the entire
view.
*/
public var pulseFill: Bool = false {
didSet {
......@@ -62,18 +60,14 @@ public class MaterialButton : UIButton {
}
}
/**
:name: pulseColorOpacity
*/
/// The opcaity value for the pulse animation.
public var pulseColorOpacity: CGFloat = 0.25 {
didSet {
updatePulseLayer()
}
}
/**
:name: pulseColor
*/
/// The color of the pulse effect.
public var pulseColor: UIColor? {
didSet {
updatePulseLayer()
......@@ -81,7 +75,10 @@ public class MaterialButton : UIButton {
}
/**
:name: masksToBounds
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using
the image property, then this value does not need to be set, since the
visualLayer's maskToBounds is set to true by default.
*/
public var masksToBounds: Bool {
get {
......@@ -92,18 +89,14 @@ public class MaterialButton : UIButton {
}
}
/**
:name: backgroundColor
*/
/// A property that accesses the backing layer's backgroundColor.
public override var backgroundColor: UIColor? {
didSet {
layer.backgroundColor = backgroundColor?.CGColor
}
}
/**
:name: x
*/
/// A property that accesses the layer.frame.origin.x property.
public var x: CGFloat {
get {
return layer.frame.origin.x
......@@ -113,9 +106,7 @@ public class MaterialButton : UIButton {
}
}
/**
:name: y
*/
/// A property that accesses the layer.frame.origin.y property.
public var y: CGFloat {
get {
return layer.frame.origin.y
......@@ -126,7 +117,10 @@ public class MaterialButton : UIButton {
}
/**
:name: width
A property that accesses the layer.frame.origin.width property.
When setting this property in conjunction with the shape property having a
value that is not .None, the height will be adjusted to maintain the correct
shape.
*/
public var width: CGFloat {
get {
......@@ -141,7 +135,10 @@ public class MaterialButton : UIButton {
}
/**
:name: height
A property that accesses the layer.frame.origin.height property.
When setting this property in conjunction with the shape property having a
value that is not .None, the width will be adjusted to maintain the correct
shape.
*/
public var height: CGFloat {
get {
......@@ -155,18 +152,14 @@ public class MaterialButton : UIButton {
}
}
/**
:name: shadowColor
*/
/// A property that accesses the backing layer's shadowColor.
public var shadowColor: UIColor? {
didSet {
layer.shadowColor = shadowColor?.CGColor
}
}
/**
:name: shadowOffset
*/
/// A property that accesses the backing layer's shadowOffset.
public var shadowOffset: CGSize {
get {
return layer.shadowOffset
......@@ -176,9 +169,7 @@ public class MaterialButton : UIButton {
}
}
/**
:name: shadowOpacity
*/
/// A property that accesses the backing layer's shadowOpacity.
public var shadowOpacity: Float {
get {
return layer.shadowOpacity
......@@ -188,9 +179,7 @@ public class MaterialButton : UIButton {
}
}
/**
:name: shadowRadius
*/
/// A property that accesses the backing layer's shadowRadius.
public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
......@@ -201,7 +190,9 @@ public class MaterialButton : UIButton {
}
/**
:name: depth
A property that sets the shadowOffset, shadowOpacity, and shadowRadius
for the backing layer. This is the preferred method of setting depth
in order to maintain consitency across UI objects.
*/
public var depth: MaterialDepth {
didSet {
......@@ -213,9 +204,11 @@ public class MaterialButton : UIButton {
}
/**
:name: cornerRadius
A property that sets the cornerRadius of the backing layer. If the shape
property has a value of .Circle when the cornerRadius is set, it will
become .None, as it no longer maintains its circle shape.
*/
public var cornerRadius: MaterialRadius? {
public var cornerRadius: MaterialRadius {
didSet {
if let v: MaterialRadius = cornerRadius {
layer.cornerRadius = MaterialRadiusToValue(v)
......@@ -227,7 +220,9 @@ public class MaterialButton : UIButton {
}
/**
:name: shape
A property that manages the overall shape for the object. If either the
width or height property is set, the other will be automatically adjusted
to maintain the shape of the object.
*/
public var shape: MaterialShape {
didSet {
......@@ -242,7 +237,8 @@ public class MaterialButton : UIButton {
}
/**
:name: borderWidth
A property that accesses the layer.borderWith using a MaterialBorder
enum preset.
*/
public var borderWidth: MaterialBorder {
didSet {
......@@ -250,18 +246,14 @@ public class MaterialButton : UIButton {
}
}
/**
:name: borderColor
*/
/// A property that accesses the layer.borderColor property.
public var borderColor: UIColor? {
didSet {
layer.borderColor = borderColor?.CGColor
}
}
/**
:name: position
*/
/// A property that accesses the layer.position property.
public var position: CGPoint {
get {
return layer.position
......@@ -271,9 +263,7 @@ public class MaterialButton : UIButton {
}
}
/**
:name: zPosition
*/
/// A property that accesses the layer.zPosition property.
public var zPosition: CGFloat {
get {
return layer.zPosition
......@@ -294,38 +284,41 @@ public class MaterialButton : UIButton {
}
/**
:name: init
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
borderWidth = .None
depth = .None
shape = .None
cornerRadius = .None
contentInsets = .None
super.init(coder: aDecoder)
prepareView()
}
/**
:name: init
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
*/
public override init(frame: CGRect) {
borderWidth = .None
depth = .None
shape = .None
cornerRadius = .None
contentInsets = .None
super.init(frame: frame)
prepareView()
}
/**
:name: init
*/
/// A convenience initializer that is mostly used with AutoLayout.
public convenience init() {
self.init(frame: CGRectNull)
}
/**
:name: layoutSublayersOfLayer
*/
/// Overriding the layout callback for layer sublayers.
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
......@@ -335,7 +328,9 @@ public class MaterialButton : UIButton {
}
/**
:name: animate
A method that accepts CAAnimation objects and executes them on the
view's backing layer.
- Parameter animation: A CAAnimation instance.
*/
public func animate(animation: CAAnimation) {
animation.delegate = self
......@@ -352,14 +347,21 @@ public class MaterialButton : UIButton {
}
/**
:name: animationDidStart
A delegation method that is executed when the backing layer starts
running an animation.
- Parameter anim: The currently running CAAnimation instance.
*/
public override func animationDidStart(anim: CAAnimation) {
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStart?(anim)
}
/**
:name: animationDidStop
A delegation method that is executed when the backing layer stops
running an animation.
- Parameter anim: The CAAnimation instance that stopped running.
- Parameter flag: A boolean that indicates if the animation stopped
because it was completed or interrupted. True if completed, false
if interrupted.
*/
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
......@@ -379,7 +381,10 @@ public class MaterialButton : UIButton {
}
/**
:name: touchesBegan
A delegation method that is executed when the view has began a
touch event.
- Parameter touches: A set of UITouch objects.
- Parameter event: A UIEvent object.
*/
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
......@@ -409,7 +414,10 @@ public class MaterialButton : UIButton {
}
/**
:name: touchesMoved
A delegation method that is executed when the view touch event is
moving.
- Parameter touches: A set of UITouch objects.
- Parameter event: A UIEvent object.
*/
public override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesMoved(touches, withEvent: event)
......@@ -424,7 +432,10 @@ public class MaterialButton : UIButton {
}
/**
:name: touchesEnded
A delegation method that is executed when the view touch event has
ended.
- Parameter touches: A set of UITouch objects.
- Parameter event: A UIEvent object.
*/
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
......@@ -432,7 +443,10 @@ public class MaterialButton : UIButton {
}
/**
:name: touchesCancelled
A delegation method that is executed when the view touch event has
been cancelled.
- Parameter touches: A set of UITouch objects.
- Parameter event: A UIEvent object.
*/
public override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
......@@ -447,59 +461,55 @@ public class MaterialButton : UIButton {
}
/**
:name: prepareView
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public func prepareView() {
prepareVisualLayer()
preparePulseLayer()
shadowColor = MaterialColor.black
borderColor = MaterialColor.black
pulseColor = MaterialColor.white
pulseColorOpacity = 0.25
}
/**
:name: prepareVisualLayer
*/
/// Prepares the visualLayer property.
internal func prepareVisualLayer() {
visualLayer.zPosition = 0
visualLayer.masksToBounds = true
layer.addSublayer(visualLayer)
}
/**
:name: layoutVisualLayer
*/
/// Manages the layout for the visualLayer property.
internal func layoutVisualLayer() {
visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius
}
/**
:name: layoutShape
*/
/// Manages the layout for the shape of the view instance.
internal func layoutShape() {
if .Circle == shape {
layer.cornerRadius = width / 2
}
}
/**
:name: preparePulseLayer
*/
/// Prepares the pulseLayer property.
internal func preparePulseLayer() {
pulseLayer.hidden = true
pulseLayer.zPosition = 1
visualLayer.addSublayer(pulseLayer)
}
/**
:name: updatePulseLayer
*/
/// Updates the pulseLayer when settings have changed.
internal func updatePulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
}
/**
:name: shrink
*/
/// Executes the shrink animation for the pulse effect.
internal func shrinkAnimation() {
let t: CFTimeInterval = 0.25
let s: CGFloat = 1
......
......@@ -24,13 +24,14 @@ public protocol MaterialDelegate {}
@objc(MaterialLayer)
public class MaterialLayer : CAShapeLayer {
/**
:name: visualLayer
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
allows the dropshadow effect on the backing layer, while clipping
the image to a desired shape within the visualLayer.
*/
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
/**
:name: x
*/
/// A property that accesses the layer.frame.origin.x property.
public var x: CGFloat {
get {
return frame.origin.x
......@@ -40,9 +41,7 @@ public class MaterialLayer : CAShapeLayer {
}
}
/**
:name: y
*/
/// A property that accesses the layer.frame.origin.y property.
public var y: CGFloat {
get {
return frame.origin.y
......@@ -53,7 +52,10 @@ public class MaterialLayer : CAShapeLayer {
}
/**
:name: width
A property that accesses the layer.frame.origin.width property.
When setting this property in conjunction with the shape property having a
value that is not .None, the height will be adjusted to maintain the correct
shape.
*/
public var width: CGFloat {
get {
......@@ -68,7 +70,10 @@ public class MaterialLayer : CAShapeLayer {
}
/**
:name: height
A property that accesses the layer.frame.origin.height property.
When setting this property in conjunction with the shape property having a
value that is not .None, the width will be adjusted to maintain the correct
shape.
*/
public var height: CGFloat {
get {
......@@ -83,56 +88,51 @@ public class MaterialLayer : CAShapeLayer {
}
/**
:name: image
A property that manages an image for the visualLayer's contents
property. Images should not be set to the backing layer's contents
property to avoid conflicts when using clipsToBounds.
*/
public var image: UIImage? {
get {
return nil == visualLayer.contents ? nil : UIImage(CGImage: visualLayer.contents as! CGImageRef)
}
set(value) {
visualLayer.contents = value?.CGImage
didSet {
visualLayer.contents = image?.CGImage
}
}
/**
:name: contentsRect
Allows a relative subrectangle within the range of 0 to 1 to be
specified for the visualLayer's contents property. This allows
much greater flexibility than the contentsGravity property in
terms of how the image is cropped and stretched.
*/
public override var contentsRect: CGRect {
get {
return visualLayer.contentsRect
}
set(value) {
didSet {
visualLayer.contentsRect = contentsRect
}
}
/**
:name: contentsCenter
A CGRect that defines a stretchable region inside the visualLayer
with a fixed border around the edge.
*/
public override var contentsCenter: CGRect {
get {
return visualLayer.contentsCenter
}
set(value) {
didSet {
visualLayer.contentsCenter = contentsCenter
}
}
/**
:name: contentsScale
A floating point value that defines a ratio between the pixel
dimensions of the visualLayer's contents property and the size
of the layer. By default, this value is set to the UIScreen's
scale value, UIScreen.mainScreen().scale.
*/
public override var contentsScale: CGFloat {
get {
return visualLayer.contentsScale
}
set(value) {
didSet {
visualLayer.contentsScale = contentsScale
}
}
/**
:name: contentsGravity
*/
/// Determines how content should be aligned within the visualLayer's bounds.
public override var contentsGravity: String {
get {
return visualLayer.contentsGravity
......@@ -143,7 +143,9 @@ public class MaterialLayer : CAShapeLayer {
}
/**
:name: depth
A property that sets the shadowOffset, shadowOpacity, and shadowRadius
for the backing layer. This is the preferred method of setting depth
in order to maintain consitency across UI objects.
*/
public var depth: MaterialDepth {
didSet {
......@@ -155,7 +157,9 @@ public class MaterialLayer : CAShapeLayer {
}
/**
:name: cornerRadius
A property that sets the cornerRadius of the backing layer. If the shape
property has a value of .Circle when the cornerRadius is set, it will
become .None, as it no longer maintains its circle shape.
*/
public override var cornerRadius: CGFloat {
didSet {
......@@ -166,22 +170,25 @@ public class MaterialLayer : CAShapeLayer {
}
/**
:name: shape
A property that manages the overall shape for the object. If either the
width or height property is set, the other will be automatically adjusted
to maintain the shape of the object.
*/
public var shape: MaterialShape {
didSet {
if .None != shape {
if width < height {
width = height
frame.size.width = height
} else {
height = width
frame.size.height = width
}
}
}
}
/**
:name: init
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
shape = .None
......@@ -191,7 +198,9 @@ public class MaterialLayer : CAShapeLayer {
}
/**
:name: init
An initializer the same as init(). The layer parameter is ignored
to avoid crashes on certain architectures.
- Parameter layer: AnyObject.
*/
public override init(layer: AnyObject) {
shape = .None
......@@ -200,9 +209,7 @@ public class MaterialLayer : CAShapeLayer {
prepareVisualLayer()
}
/**
:name: init
*/
/// A convenience initializer.
public override init() {
shape = .None
depth = .None
......@@ -211,7 +218,8 @@ public class MaterialLayer : CAShapeLayer {
}
/**
:name: init
An initializer that initializes the object with a CGRect object.
- Parameter frame: A CGRect instance.
*/
public convenience init(frame: CGRect) {
self.init()
......@@ -225,7 +233,8 @@ public class MaterialLayer : CAShapeLayer {
}
/**
:name: animate
A method that accepts CAAnimation objects and executes.
- Parameter animation: A CAAnimation instance.
*/
public func animate(animation: CAAnimation) {
animation.delegate = self
......@@ -242,14 +251,21 @@ public class MaterialLayer : CAShapeLayer {
}
/**
:name: animationDidStart
A delegation method that is executed when the layer starts
running an animation.
- Parameter anim: The currently running CAAnimation instance.
*/
public override func animationDidStart(anim: CAAnimation) {
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStart?(anim)
}
/**
:name: animationDidStop
A delegation method that is executed when the layer stops
running an animation.
- Parameter anim: The CAAnimation instance that stopped running.
- Parameter flag: A boolean that indicates if the animation stopped
because it was completed or interrupted. True if completed, false
if interrupted.
*/
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
......@@ -268,9 +284,7 @@ public class MaterialLayer : CAShapeLayer {
layoutVisualLayer()
}
/**
:name: prepareVisualLayer
*/
/// Prepares the visualLayer property.
public func prepareVisualLayer() {
// visualLayer
visualLayer.zPosition = 0
......@@ -278,21 +292,17 @@ public class MaterialLayer : CAShapeLayer {
addSublayer(visualLayer)
}
/**
:name: layoutShape
*/
internal func layoutShape() {
if .Circle == shape {
cornerRadius = width / 2
}
}
/**
:name: layoutVisualLayer
*/
/// Manages the layout for the visualLayer property.
internal func layoutVisualLayer() {
visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = cornerRadius
}
/// Manages the layout for the shape of the layer instance.
internal func layoutShape() {
if .Circle == shape {
cornerRadius = width / 2
}
}
}
......@@ -49,14 +49,14 @@ public class MaterialPulseView : MaterialView {
/// The opcaity value for the pulse animation.
public var pulseColorOpacity: CGFloat = 0.25 {
didSet {
updatedPulseLayer()
updatePulseLayer()
}
}
/// The color of the pulse effect.
public var pulseColor: UIColor? {
didSet {
updatedPulseLayer()
updatePulseLayer()
}
}
......@@ -154,7 +154,7 @@ public class MaterialPulseView : MaterialView {
}
/// Updates the pulseLayer when settings have changed.
internal func updatedPulseLayer() {
internal func updatePulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
}
......
......@@ -25,9 +25,6 @@ public struct MaterialTheme {
public struct captureView {}
public struct textLayer {}
public struct label {}
public struct flatButton {}
public struct raisedButton {}
public struct fabButton {}
}
// basicCardView
......@@ -208,95 +205,3 @@ public extension MaterialTheme.label {
public static var font: UIFont = RobotoFont.regular
}
// flatButton
public extension MaterialTheme.flatButton {
// shadow
public static var depth: MaterialDepth = .None
public static var shadowColor: UIColor = MaterialColor.black
// shape
public static var cornerRadius: MaterialRadius = .Radius1
public static var contentInsets: MaterialEdgeInsets = .WideRectangle3
public static var shape: MaterialShape = .None
// border
public static var borderWidth: MaterialBorder = .None
public static var bordercolor: UIColor = MaterialColor.black
// color
public static var backgroundColor: UIColor = MaterialColor.clear
public static var pulseColor: UIColor = MaterialColor.blue.accent3
public static var pulseColorOpacity: CGFloat = 0.25
public static var titleLabelColorForNormalState: UIColor = MaterialColor.blue.accent3
// interaction
public static var userInteractionEnabled: Bool = true
// position
public static var zPosition: CGFloat = 200
// font
public static var titleLabelFont: UIFont = RobotoFont.regular
}
// raisedButton
public extension MaterialTheme.raisedButton {
// shadow
public static var depth: MaterialDepth = .Depth2
public static var shadowColor: UIColor = MaterialColor.black
// shape
public static var cornerRadius: MaterialRadius = .Radius1
public static var contentInsets: MaterialEdgeInsets = .WideRectangle2
public static var shape: MaterialShape = .None
// border
public static var borderWidth: MaterialBorder = .None
public static var bordercolor: UIColor = MaterialColor.black
// color
public static var backgroundColor: UIColor = MaterialColor.blue.accent3
public static var pulseColor: UIColor = MaterialColor.white
public static var pulseColorOpacity: CGFloat = 0.25
public static var titleLabelColorForNormalState: UIColor = MaterialColor.white
// interaction
public static var userInteractionEnabled: Bool = true
// position
public static var zPosition: CGFloat = 200
// font
public static var titleLabelFont: UIFont = RobotoFont.regular
}
// fabButton
public extension MaterialTheme.fabButton {
// shadow
public static var depth: MaterialDepth = .Depth2
public static var shadowColor: UIColor = MaterialColor.black
// shape
public static var contentInsets: MaterialEdgeInsets = .None
public static var shape: MaterialShape = .Circle
// border
public static var borderWidth: MaterialBorder = .None
public static var bordercolor: UIColor = MaterialColor.black
// color
public static var backgroundColor: UIColor = MaterialColor.red.darken1
public static var pulseColor: UIColor = MaterialColor.white
public static var pulseColorOpacity: CGFloat = 0.25
public static var titleLabelColorForNormalState: UIColor = MaterialColor.white
// interaction
public static var userInteractionEnabled: Bool = true
// position
public static var zPosition: CGFloat = 200
// font
public static var titleLabelFont: UIFont = RobotoFont.regular
}
......@@ -20,25 +20,18 @@ import UIKit
public class RaisedButton : MaterialButton {
/**
:name: prepareView
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public override func prepareView() {
super.prepareView()
setTitleColor(MaterialTheme.raisedButton.titleLabelColorForNormalState, forState: .Normal)
titleLabel!.font = MaterialTheme.raisedButton.titleLabelFont
userInteractionEnabled = MaterialTheme.raisedButton.userInteractionEnabled
backgroundColor = MaterialTheme.raisedButton.backgroundColor
pulseColorOpacity = MaterialTheme.raisedButton.pulseColorOpacity
pulseColor = MaterialTheme.raisedButton.pulseColor
depth = MaterialTheme.raisedButton.depth
shadowColor = MaterialTheme.raisedButton.shadowColor
zPosition = MaterialTheme.raisedButton.zPosition
cornerRadius = MaterialTheme.raisedButton.cornerRadius
borderWidth = MaterialTheme.raisedButton.borderWidth
borderColor = MaterialTheme.raisedButton.bordercolor
contentInsets = MaterialTheme.raisedButton.contentInsets
shape = MaterialTheme.raisedButton.shape
setTitleColor(MaterialColor.white, forState: .Normal)
backgroundColor = MaterialColor.blue.accent3
depth = .Depth2
cornerRadius = .Radius1
contentInsets = .WideRectangle3
}
}
\ No newline at end of file
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