From 023a906c5c5df992a6b3daafaf2510688643bc9c Mon Sep 17 00:00:00 2001 From: Ken Tominaga Date: Tue, 17 Feb 2015 12:41:13 +0900 Subject: [PATCH 1/4] Add public modifiers --- Source/MKButton.swift | 54 +++++++++---------- Source/MKImageView.swift | 56 +++++++++---------- Source/MKLabel.swift | 50 ++++++++--------- Source/MKLayer.swift | 102 +++++++++++++++++------------------ Source/MKTableViewCell.swift | 44 +++++++-------- Source/MKTextField.swift | 96 ++++++++++++++++----------------- 6 files changed, 201 insertions(+), 201 deletions(-) diff --git a/Source/MKButton.swift b/Source/MKButton.swift index 45ced72..dbbd835 100644 --- a/Source/MKButton.swift +++ b/Source/MKButton.swift @@ -9,78 +9,78 @@ import UIKit @IBDesignable -class MKButton : UIButton +public class MKButton : UIButton { - @IBInspectable var maskEnabled: Bool = true { + @IBInspectable public var maskEnabled: Bool = true { didSet { mkLayer.enableMask(enable: maskEnabled) } } - @IBInspectable var rippleLocation: MKRippleLocation = .TapLocation { + @IBInspectable public var rippleLocation: MKRippleLocation = .TapLocation { didSet { mkLayer.rippleLocation = rippleLocation } } - @IBInspectable var circleGrowRatioMax: Float = 0.9 { + @IBInspectable public var circleGrowRatioMax: Float = 0.9 { didSet { mkLayer.circleGrowRatioMax = circleGrowRatioMax } } - @IBInspectable var backgroundLayerCornerRadius: CGFloat = 0.0 { + @IBInspectable public var backgroundLayerCornerRadius: CGFloat = 0.0 { didSet { mkLayer.setBackgroundLayerCornerRadius(backgroundLayerCornerRadius) } } // animations - @IBInspectable var shadowAniEnabled: Bool = true - @IBInspectable var backgroundAniEnabled: Bool = true { + @IBInspectable public var shadowAniEnabled: Bool = true + @IBInspectable public var backgroundAniEnabled: Bool = true { didSet { if !backgroundAniEnabled { mkLayer.enableOnlyCircleLayer() } } } - @IBInspectable var aniDuration: Float = 0.65 - @IBInspectable var circleAniTimingFunction: MKTimingFunction = .Linear - @IBInspectable var backgroundAniTimingFunction: MKTimingFunction = .Linear - @IBInspectable var shadowAniTimingFunction: MKTimingFunction = .EaseOut - - @IBInspectable var cornerRadius: CGFloat = 2.5 { + @IBInspectable public var aniDuration: Float = 0.65 + @IBInspectable public var circleAniTimingFunction: MKTimingFunction = .Linear + @IBInspectable public var backgroundAniTimingFunction: MKTimingFunction = .Linear + @IBInspectable public var shadowAniTimingFunction: MKTimingFunction = .EaseOut + + @IBInspectable public var cornerRadius: CGFloat = 2.5 { didSet { layer.cornerRadius = cornerRadius mkLayer.setMaskLayerCornerRadius(cornerRadius) } } // color - @IBInspectable var circleLayerColor: UIColor = UIColor(white: 0.45, alpha: 0.5) { + @IBInspectable public var circleLayerColor: UIColor = UIColor(white: 0.45, alpha: 0.5) { didSet { mkLayer.setCircleLayerColor(circleLayerColor) } } - @IBInspectable var backgroundLayerColor: UIColor = UIColor(white: 0.75, alpha: 0.25) { + @IBInspectable public var backgroundLayerColor: UIColor = UIColor(white: 0.75, alpha: 0.25) { didSet { mkLayer.setBackgroundLayerColor(backgroundLayerColor) } } - override var bounds: CGRect { + override public var bounds: CGRect { didSet { mkLayer.superLayerDidResize() } } - + private lazy var mkLayer: MKLayer = MKLayer(superLayer: self.layer) - + // MARK - initilization - override init(frame: CGRect) { + override public init(frame: CGRect) { super.init(frame: frame) setupLayer() } - required init(coder aDecoder: NSCoder) { + required public init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setupLayer() } - + // MARK - setup methods private func setupLayer() { adjustsImageWhenHighlighted = false @@ -88,33 +88,33 @@ class MKButton : UIButton mkLayer.setBackgroundLayerColor(backgroundLayerColor) mkLayer.setCircleLayerColor(circleLayerColor) } - + // MARK - location tracking methods override func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent) -> Bool { if rippleLocation == .TapLocation { mkLayer.didChangeTapLocation(touch.locationInView(self)) } - + // circleLayer animation mkLayer.animateScaleForCircleLayer(0.45, toScale: 1.0, timingFunction: circleAniTimingFunction, duration: CFTimeInterval(aniDuration)) - + // backgroundLayer animation if backgroundAniEnabled { mkLayer.animateAlphaForBackgroundLayer(backgroundAniTimingFunction, duration: CFTimeInterval(aniDuration)) } - + // shadow animation for self if shadowAniEnabled { let shadowRadius = self.layer.shadowRadius let shadowOpacity = self.layer.shadowOpacity - + //if mkType == .Flat { // mkLayer.animateMaskLayerShadow() //} else { mkLayer.animateSuperLayerShadow(10, toRadius: shadowRadius, fromOpacity: 0, toOpacity: shadowOpacity, timingFunction: shadowAniTimingFunction, duration: CFTimeInterval(aniDuration)) //} } - + return super.beginTrackingWithTouch(touch, withEvent: event) } } diff --git a/Source/MKImageView.swift b/Source/MKImageView.swift index 589439f..4c1bdbb 100644 --- a/Source/MKImageView.swift +++ b/Source/MKImageView.swift @@ -9,100 +9,100 @@ import UIKit @IBDesignable -class MKImageView: UIImageView +public class MKImageView: UIImageView { - @IBInspectable var maskEnabled: Bool = true { + @IBInspectable public var maskEnabled: Bool = true { didSet { mkLayer.enableMask(enable: maskEnabled) } } - @IBInspectable var rippleLocation: MKRippleLocation = .TapLocation { + @IBInspectable public var rippleLocation: MKRippleLocation = .TapLocation { didSet { mkLayer.rippleLocation = rippleLocation } } - @IBInspectable var aniDuration: Float = 0.65 - @IBInspectable var circleAniTimingFunction: MKTimingFunction = .Linear - @IBInspectable var backgroundAniTimingFunction: MKTimingFunction = .Linear - @IBInspectable var backgroundAniEnabled: Bool = true { + @IBInspectable public var aniDuration: Float = 0.65 + @IBInspectable public var circleAniTimingFunction: MKTimingFunction = .Linear + @IBInspectable public var backgroundAniTimingFunction: MKTimingFunction = .Linear + @IBInspectable public var backgroundAniEnabled: Bool = true { didSet { if !backgroundAniEnabled { mkLayer.enableOnlyCircleLayer() } } } - @IBInspectable var circleGrowRatioMax: Float = 0.9 { + @IBInspectable public var circleGrowRatioMax: Float = 0.9 { didSet { mkLayer.circleGrowRatioMax = circleGrowRatioMax } } - - @IBInspectable var cornerRadius: CGFloat = 2.5 { + + @IBInspectable public var cornerRadius: CGFloat = 2.5 { didSet { layer.cornerRadius = cornerRadius mkLayer.setMaskLayerCornerRadius(cornerRadius) } } // color - @IBInspectable var circleLayerColor: UIColor = UIColor(white: 0.45, alpha: 0.5) { + @IBInspectable public var circleLayerColor: UIColor = UIColor(white: 0.45, alpha: 0.5) { didSet { mkLayer.setCircleLayerColor(circleLayerColor) } } - @IBInspectable var backgroundLayerColor: UIColor = UIColor(white: 0.75, alpha: 0.25) { + @IBInspectable public var backgroundLayerColor: UIColor = UIColor(white: 0.75, alpha: 0.25) { didSet { mkLayer.setBackgroundLayerColor(backgroundLayerColor) } } - override var bounds: CGRect { + override public var bounds: CGRect { didSet { mkLayer.superLayerDidResize() } } private lazy var mkLayer: MKLayer = MKLayer(superLayer: self.layer) - - override init() { + + override public init() { super.init() setup() } - - required init(coder aDecoder: NSCoder) { + + required public init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setup() } - - override init(frame: CGRect) { + + override public init(frame: CGRect) { super.init(frame: frame) setup() } - - override init(image: UIImage!) { + + override public init(image: UIImage!) { super.init(image: image) setup() } - - override init(image: UIImage!, highlightedImage: UIImage?) { + + override public init(image: UIImage!, highlightedImage: UIImage?) { super.init(image: image, highlightedImage: highlightedImage) setup() } - + private func setup() { mkLayer.setCircleLayerColor(circleLayerColor) mkLayer.setBackgroundLayerColor(backgroundLayerColor) mkLayer.setMaskLayerCornerRadius(cornerRadius) } - - func animateRipple(location: CGPoint? = nil) { + + public func animateRipple(location: CGPoint? = nil) { if let point = location { mkLayer.didChangeTapLocation(point) } else if rippleLocation == .TapLocation { rippleLocation = .Center } - + mkLayer.animateScaleForCircleLayer(0.65, toScale: 1.0, timingFunction: circleAniTimingFunction, duration: CFTimeInterval(aniDuration)) mkLayer.animateAlphaForBackgroundLayer(backgroundAniTimingFunction, duration: CFTimeInterval(aniDuration)) } - + override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { super.touchesBegan(touches, withEvent: event) if let firstTouch = touches.anyObject() as? UITouch { diff --git a/Source/MKLabel.swift b/Source/MKLabel.swift index ee38258..85bbda1 100644 --- a/Source/MKLabel.swift +++ b/Source/MKLabel.swift @@ -8,90 +8,90 @@ import UIKit -class MKLabel: UILabel { - @IBInspectable var maskEnabled: Bool = true { +public class MKLabel: UILabel { + @IBInspectable public var maskEnabled: Bool = true { didSet { mkLayer.enableMask(enable: maskEnabled) } } - @IBInspectable var rippleLocation: MKRippleLocation = .TapLocation { + @IBInspectable public var rippleLocation: MKRippleLocation = .TapLocation { didSet { mkLayer.rippleLocation = rippleLocation } } - @IBInspectable var aniDuration: Float = 0.65 - @IBInspectable var circleAniTimingFunction: MKTimingFunction = .Linear - @IBInspectable var backgroundAniTimingFunction: MKTimingFunction = .Linear - @IBInspectable var backgroundAniEnabled: Bool = true { + @IBInspectable public var aniDuration: Float = 0.65 + @IBInspectable public var circleAniTimingFunction: MKTimingFunction = .Linear + @IBInspectable public var backgroundAniTimingFunction: MKTimingFunction = .Linear + @IBInspectable public var backgroundAniEnabled: Bool = true { didSet { if !backgroundAniEnabled { mkLayer.enableOnlyCircleLayer() } } } - @IBInspectable var circleGrowRatioMax: Float = 0.9 { + @IBInspectable public var circleGrowRatioMax: Float = 0.9 { didSet { mkLayer.circleGrowRatioMax = circleGrowRatioMax } } - - @IBInspectable var cornerRadius: CGFloat = 2.5 { + + @IBInspectable public var cornerRadius: CGFloat = 2.5 { didSet { layer.cornerRadius = cornerRadius mkLayer.setMaskLayerCornerRadius(cornerRadius) } } // color - @IBInspectable var circleLayerColor: UIColor = UIColor(white: 0.45, alpha: 0.5) { + @IBInspectable public var circleLayerColor: UIColor = UIColor(white: 0.45, alpha: 0.5) { didSet { mkLayer.setCircleLayerColor(circleLayerColor) } } - @IBInspectable var backgroundLayerColor: UIColor = UIColor(white: 0.75, alpha: 0.25) { + @IBInspectable public var backgroundLayerColor: UIColor = UIColor(white: 0.75, alpha: 0.25) { didSet { mkLayer.setBackgroundLayerColor(backgroundLayerColor) } } - override var bounds: CGRect { + override public var bounds: CGRect { didSet { mkLayer.superLayerDidResize() } } private lazy var mkLayer: MKLayer = MKLayer(superLayer: self.layer) - - override init() { + + override public init() { super.init() setup() } - - required init(coder aDecoder: NSCoder) { + + required public init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setup() } - - override init(frame: CGRect) { + + override public init(frame: CGRect) { super.init(frame: frame) setup() } - + private func setup() { mkLayer.setCircleLayerColor(circleLayerColor) mkLayer.setBackgroundLayerColor(backgroundLayerColor) mkLayer.setMaskLayerCornerRadius(cornerRadius) } - - func animateRipple(location: CGPoint? = nil) { + + public func animateRipple(location: CGPoint? = nil) { if let point = location { mkLayer.didChangeTapLocation(point) } else if rippleLocation == .TapLocation { rippleLocation = .Center } - + mkLayer.animateScaleForCircleLayer(0.65, toScale: 1.0, timingFunction: circleAniTimingFunction, duration: CFTimeInterval(aniDuration)) mkLayer.animateAlphaForBackgroundLayer(backgroundAniTimingFunction, duration: CFTimeInterval(aniDuration)) } - - override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { + + override public func touchesBegan(touches: NSSet, withEvent event: UIEvent) { super.touchesBegan(touches, withEvent: event) if let firstTouch = touches.anyObject() as? UITouch { let location = firstTouch.locationInView(self) diff --git a/Source/MKLayer.swift b/Source/MKLayer.swift index 2614673..5816a50 100644 --- a/Source/MKLayer.swift +++ b/Source/MKLayer.swift @@ -9,13 +9,13 @@ import UIKit import QuartzCore -enum MKTimingFunction { +public enum MKTimingFunction { case Linear case EaseIn case EaseOut case Custom(Float, Float, Float, Float) - - var function : CAMediaTimingFunction { + + public var function : CAMediaTimingFunction { switch self { case .Linear: return CAMediaTimingFunction(name: "linear") @@ -29,19 +29,19 @@ enum MKTimingFunction { } } -enum MKRippleLocation { +public enum MKRippleLocation { case Center case Left case Right case TapLocation } -class MKLayer { +public class MKLayer { private var superLayer: CALayer! private let circleLayer = CALayer() private let backgroundLayer = CALayer() private let maskLayer = CAShapeLayer() - var rippleLocation: MKRippleLocation = .TapLocation { + public var rippleLocation: MKRippleLocation = .TapLocation { didSet { var origin: CGPoint? switch rippleLocation { @@ -59,47 +59,47 @@ class MKLayer { } } } - - var circleGrowRatioMax: Float = 0.9 { + + public var circleGrowRatioMax: Float = 0.9 { didSet { if circleGrowRatioMax > 0 { let superLayerWidth = CGRectGetWidth(superLayer.bounds) let superLayerHeight = CGRectGetHeight(superLayer.bounds) let circleSize = CGFloat(max(superLayerWidth, superLayerHeight)) * CGFloat(circleGrowRatioMax) let circleCornerRadius = circleSize/2 - + circleLayer.cornerRadius = circleCornerRadius setCircleLayerLocationAt(CGPoint(x: superLayerWidth/2, y: superLayerHeight/2)) } } } - - init(superLayer: CALayer) { + + public init(superLayer: CALayer) { self.superLayer = superLayer - + let superLayerWidth = CGRectGetWidth(superLayer.bounds) let superLayerHeight = CGRectGetHeight(superLayer.bounds) - + // background layer backgroundLayer.frame = superLayer.bounds backgroundLayer.opacity = 0.0 superLayer.addSublayer(backgroundLayer) - + // circlelayer let circleSize = CGFloat(max(superLayerWidth, superLayerHeight)) * CGFloat(circleGrowRatioMax) let circleCornerRadius = circleSize/2 - + circleLayer.opacity = 0.0 circleLayer.cornerRadius = circleCornerRadius setCircleLayerLocationAt(CGPoint(x: superLayerWidth/2, y: superLayerHeight/2)) backgroundLayer.addSublayer(circleLayer) - + // mask layer setMaskLayerCornerRadius(superLayer.cornerRadius) backgroundLayer.mask = maskLayer } - - func superLayerDidResize() { + + public func superLayerDidResize() { CATransaction.begin() CATransaction.setDisableActions(true) backgroundLayer.frame = superLayer.bounds @@ -107,38 +107,38 @@ class MKLayer { CATransaction.commit() setCircleLayerLocationAt(CGPoint(x: superLayer.bounds.width/2, y: superLayer.bounds.height/2)) } - - func enableOnlyCircleLayer() { + + public func enableOnlyCircleLayer() { backgroundLayer.removeFromSuperlayer() superLayer.addSublayer(circleLayer) } - - func setBackgroundLayerColor(color: UIColor) { + + public func setBackgroundLayerColor(color: UIColor) { backgroundLayer.backgroundColor = color.CGColor } - - func setCircleLayerColor(color: UIColor) { + + public func setCircleLayerColor(color: UIColor) { circleLayer.backgroundColor = color.CGColor } - - func didChangeTapLocation(location: CGPoint) { + + public func didChangeTapLocation(location: CGPoint) { if rippleLocation == .TapLocation { self.setCircleLayerLocationAt(location) } } - - func setMaskLayerCornerRadius(cornerRadius: CGFloat) { + + public func setMaskLayerCornerRadius(cornerRadius: CGFloat) { maskLayer.path = UIBezierPath(roundedRect: backgroundLayer.bounds, cornerRadius: cornerRadius).CGPath } - - func enableMask(enable: Bool = true) { + + public func enableMask(enable: Bool = true) { backgroundLayer.mask = enable ? maskLayer : nil } - - func setBackgroundLayerCornerRadius(cornerRadius: CGFloat) { + + public func setBackgroundLayerCornerRadius(cornerRadius: CGFloat) { backgroundLayer.cornerRadius = cornerRadius } - + private func setCircleLayerLocationAt(center: CGPoint) { let bounds = superLayer.bounds let width = CGRectGetWidth(bounds) @@ -146,7 +146,7 @@ class MKLayer { let subSize = CGFloat(max(width, height)) * CGFloat(circleGrowRatioMax) let subX = center.x - subSize/2 let subY = center.y - subSize/2 - + // disable animation when changing layer frame CATransaction.begin() CATransaction.setDisableActions(true) @@ -154,29 +154,29 @@ class MKLayer { circleLayer.frame = CGRect(x: subX, y: subY, width: subSize, height: subSize) CATransaction.commit() } - + // MARK - Animation - func animateScaleForCircleLayer(fromScale: Float, toScale: Float, timingFunction: MKTimingFunction, duration: CFTimeInterval) { + public func animateScaleForCircleLayer(fromScale: Float, toScale: Float, timingFunction: MKTimingFunction, duration: CFTimeInterval) { let circleLayerAnim = CABasicAnimation(keyPath: "transform.scale") circleLayerAnim.fromValue = fromScale circleLayerAnim.toValue = toScale - + let opacityAnim = CABasicAnimation(keyPath: "opacity") opacityAnim.fromValue = 1.0 opacityAnim.toValue = 0.0 - + let groupAnim = CAAnimationGroup() groupAnim.duration = duration groupAnim.timingFunction = timingFunction.function groupAnim.removedOnCompletion = false groupAnim.fillMode = kCAFillModeForwards - + groupAnim.animations = [circleLayerAnim, opacityAnim] - + circleLayer.addAnimation(groupAnim, forKey: nil) } - - func animateAlphaForBackgroundLayer(timingFunction: MKTimingFunction, duration: CFTimeInterval) { + + public func animateAlphaForBackgroundLayer(timingFunction: MKTimingFunction, duration: CFTimeInterval) { let backgroundLayerAnim = CABasicAnimation(keyPath: "opacity") backgroundLayerAnim.fromValue = 1.0 backgroundLayerAnim.toValue = 0.0 @@ -184,31 +184,31 @@ class MKLayer { backgroundLayerAnim.timingFunction = timingFunction.function backgroundLayer.addAnimation(backgroundLayerAnim, forKey: nil) } - - func animateSuperLayerShadow(fromRadius: CGFloat, toRadius: CGFloat, fromOpacity: Float, toOpacity: Float, timingFunction: MKTimingFunction, duration: CFTimeInterval) { + + public func animateSuperLayerShadow(fromRadius: CGFloat, toRadius: CGFloat, fromOpacity: Float, toOpacity: Float, timingFunction: MKTimingFunction, duration: CFTimeInterval) { animateShadowForLayer(superLayer, fromRadius: fromRadius, toRadius: toRadius, fromOpacity: fromOpacity, toOpacity: toOpacity, timingFunction: timingFunction, duration: duration) } - - func animateMaskLayerShadow() { - + + public func animateMaskLayerShadow() { + } - + private func animateShadowForLayer(layer: CALayer, fromRadius: CGFloat, toRadius: CGFloat, fromOpacity: Float, toOpacity: Float, timingFunction: MKTimingFunction, duration: CFTimeInterval) { let radiusAnimation = CABasicAnimation(keyPath: "shadowRadius") radiusAnimation.fromValue = fromRadius radiusAnimation.toValue = toRadius - + let opacityAnimation = CABasicAnimation(keyPath: "shadowOpacity") opacityAnimation.fromValue = fromOpacity opacityAnimation.toValue = toOpacity - + let groupAnimation = CAAnimationGroup() groupAnimation.duration = duration groupAnimation.timingFunction = timingFunction.function groupAnimation.removedOnCompletion = false groupAnimation.fillMode = kCAFillModeForwards groupAnimation.animations = [radiusAnimation, opacityAnimation] - + layer.addAnimation(groupAnimation, forKey: nil) } } diff --git a/Source/MKTableViewCell.swift b/Source/MKTableViewCell.swift index 2ec516f..17c8f22 100644 --- a/Source/MKTableViewCell.swift +++ b/Source/MKTableViewCell.swift @@ -8,63 +8,63 @@ import UIKit -class MKTableViewCell : UITableViewCell { - @IBInspectable var rippleLocation: MKRippleLocation = .TapLocation { +public class MKTableViewCell : UITableViewCell { + @IBInspectable public var rippleLocation: MKRippleLocation = .TapLocation { didSet { mkLayer.rippleLocation = rippleLocation } } - @IBInspectable var circleAniDuration: Float = 0.75 - @IBInspectable var backgroundAniDuration: Float = 1.0 - @IBInspectable var circleAniTimingFunction: MKTimingFunction = .Linear - @IBInspectable var shadowAniEnabled: Bool = true - + @IBInspectable public var circleAniDuration: Float = 0.75 + @IBInspectable public var backgroundAniDuration: Float = 1.0 + @IBInspectable public var circleAniTimingFunction: MKTimingFunction = .Linear + @IBInspectable public var shadowAniEnabled: Bool = true + // color - @IBInspectable var circleLayerColor: UIColor = UIColor(white: 0.45, alpha: 0.5) { + @IBInspectable public var circleLayerColor: UIColor = UIColor(white: 0.45, alpha: 0.5) { didSet { mkLayer.setCircleLayerColor(circleLayerColor) } } - @IBInspectable var backgroundLayerColor: UIColor = UIColor(white: 0.75, alpha: 0.25) { + @IBInspectable public var backgroundLayerColor: UIColor = UIColor(white: 0.75, alpha: 0.25) { didSet { mkLayer.setBackgroundLayerColor(backgroundLayerColor) } } - + private lazy var mkLayer: MKLayer = MKLayer(superLayer: self.contentView.layer) private var contentViewResized = false - - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + + override public init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) } - - override init(frame: CGRect) { + + override public init(frame: CGRect) { super.init(frame: frame) setupLayer() } - - required init(coder aDecoder: NSCoder) { + + required public init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setupLayer() } - - func setupLayer() { + + private func setupLayer() { self.selectionStyle = .None mkLayer.setBackgroundLayerColor(backgroundLayerColor) mkLayer.setCircleLayerColor(circleLayerColor) mkLayer.circleGrowRatioMax = 1.2 } - - override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { + + override public func touchesBegan(touches: NSSet, withEvent event: UIEvent) { super.touchesBegan(touches, withEvent: event) - + if let firstTouch = touches.anyObject() as? UITouch { if !contentViewResized { mkLayer.superLayerDidResize() contentViewResized = true } mkLayer.didChangeTapLocation(firstTouch.locationInView(self.contentView)) - + mkLayer.animateScaleForCircleLayer(0.65, toScale: 1.0, timingFunction: circleAniTimingFunction, duration: CFTimeInterval(circleAniDuration)) mkLayer.animateAlphaForBackgroundLayer(MKTimingFunction.Linear, duration: CFTimeInterval(backgroundAniDuration)) } diff --git a/Source/MKTextField.swift b/Source/MKTextField.swift index 4d80648..746aae2 100644 --- a/Source/MKTextField.swift +++ b/Source/MKTextField.swift @@ -10,51 +10,51 @@ import UIKit import QuartzCore @IBDesignable -class MKTextField : UITextField { - @IBInspectable var padding: CGSize = CGSize(width: 5, height: 5) - @IBInspectable var floatingLabelBottomMargin: CGFloat = 2.0 - @IBInspectable var floatingPlaceholderEnabled: Bool = false - - @IBInspectable var rippleLocation: MKRippleLocation = .TapLocation { +public class MKTextField : UITextField { + @IBInspectable public var padding: CGSize = CGSize(width: 5, height: 5) + @IBInspectable public var floatingLabelBottomMargin: CGFloat = 2.0 + @IBInspectable public var floatingPlaceholderEnabled: Bool = false + + @IBInspectable public var rippleLocation: MKRippleLocation = .TapLocation { didSet { mkLayer.rippleLocation = rippleLocation } } - - @IBInspectable var aniDuration: Float = 0.65 - @IBInspectable var circleAniTimingFunction: MKTimingFunction = .Linear - @IBInspectable var shadowAniEnabled: Bool = true - @IBInspectable var cornerRadius: CGFloat = 2.5 { + + @IBInspectable public var aniDuration: Float = 0.65 + @IBInspectable public var circleAniTimingFunction: MKTimingFunction = .Linear + @IBInspectable public var shadowAniEnabled: Bool = true + @IBInspectable public var cornerRadius: CGFloat = 2.5 { didSet { layer.cornerRadius = cornerRadius mkLayer.setMaskLayerCornerRadius(cornerRadius) } } // color - @IBInspectable var circleLayerColor: UIColor = UIColor(white: 0.45, alpha: 0.5) { + @IBInspectable public var circleLayerColor: UIColor = UIColor(white: 0.45, alpha: 0.5) { didSet { mkLayer.setCircleLayerColor(circleLayerColor) } } - @IBInspectable var backgroundLayerColor: UIColor = UIColor(white: 0.75, alpha: 0.25) { + @IBInspectable public var backgroundLayerColor: UIColor = UIColor(white: 0.75, alpha: 0.25) { didSet { mkLayer.setBackgroundLayerColor(backgroundLayerColor) } } - + // floating label - @IBInspectable var floatingLabelFont: UIFont = UIFont.boldSystemFontOfSize(10.0) { + @IBInspectable public var floatingLabelFont: UIFont = UIFont.boldSystemFontOfSize(10.0) { didSet { floatingLabel.font = floatingLabelFont } } - @IBInspectable var floatingLabelTextColor: UIColor = UIColor.lightGrayColor() { + @IBInspectable public var floatingLabelTextColor: UIColor = UIColor.lightGrayColor() { didSet { floatingLabel.textColor = floatingLabelTextColor } } - - @IBInspectable var bottomBorderEnabled: Bool = true { + + @IBInspectable public var bottomBorderEnabled: Bool = true { didSet { bottomBorderLayer?.removeFromSuperlayer() bottomBorderLayer = nil @@ -66,37 +66,37 @@ class MKTextField : UITextField { } } } - @IBInspectable var bottomBorderWidth: CGFloat = 1.0 - @IBInspectable var bottomBorderColor: UIColor = UIColor.lightGrayColor() - @IBInspectable var bottomBorderHighlightWidth: CGFloat = 1.75 - - override var placeholder: String? { + @IBInspectable public var bottomBorderWidth: CGFloat = 1.0 + @IBInspectable public var bottomBorderColor: UIColor = UIColor.lightGrayColor() + @IBInspectable public var bottomBorderHighlightWidth: CGFloat = 1.75 + + override public var placeholder: String? { didSet { floatingLabel.text = placeholder floatingLabel.sizeToFit() setFloatingLabelOverlapTextField() } } - override var bounds: CGRect { + override public var bounds: CGRect { didSet { mkLayer.superLayerDidResize() } } - + private lazy var mkLayer: MKLayer = MKLayer(superLayer: self.layer) private var floatingLabel: UILabel! private var bottomBorderLayer: CALayer? - - override init(frame: CGRect) { + + override public init(frame: CGRect) { super.init(frame: frame) setupLayer() } - - required init(coder aDecoder: NSCoder) { + + required public init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setupLayer() } - + private func setupLayer() { self.cornerRadius = 2.5 self.layer.borderWidth = 1.0 @@ -104,30 +104,30 @@ class MKTextField : UITextField { mkLayer.circleGrowRatioMax = 1.0 mkLayer.setBackgroundLayerColor(backgroundLayerColor) mkLayer.setCircleLayerColor(circleLayerColor) - + // floating label floatingLabel = UILabel() floatingLabel.font = floatingLabelFont floatingLabel.alpha = 0.0 self.addSubview(floatingLabel) } - - override func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent) -> Bool { + + override public func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent) -> Bool { mkLayer.didChangeTapLocation(touch.locationInView(self)) - + mkLayer.animateScaleForCircleLayer(0.45, toScale: 1.0, timingFunction: MKTimingFunction.Linear, duration: 0.75) mkLayer.animateAlphaForBackgroundLayer(MKTimingFunction.Linear, duration: 0.75) - + return super.beginTrackingWithTouch(touch, withEvent: event) } - + override func layoutSubviews() { super.layoutSubviews() - + if !floatingPlaceholderEnabled { return } - + if !self.text.isEmpty { floatingLabel.textColor = self.isFirstResponder() ? self.tintColor : floatingLabelTextColor if floatingLabel.alpha == 0 { @@ -136,32 +136,32 @@ class MKTextField : UITextField { } else { self.hideFloatingLabel() } - + bottomBorderLayer?.backgroundColor = self.isFirstResponder() ? self.tintColor.CGColor : bottomBorderColor.CGColor let borderWidth = self.isFirstResponder() ? bottomBorderHighlightWidth : bottomBorderWidth bottomBorderLayer?.frame = CGRect(x: 0, y: self.layer.bounds.height - borderWidth, width: self.layer.bounds.width, height: borderWidth) } - - override func textRectForBounds(bounds: CGRect) -> CGRect { + + override public func textRectForBounds(bounds: CGRect) -> CGRect { let rect = super.textRectForBounds(bounds) var newRect = CGRect(x: rect.origin.x + padding.width, y: rect.origin.y, width: rect.size.width - 2*padding.width, height: rect.size.height) - + if !floatingPlaceholderEnabled { return newRect } - + if !self.text.isEmpty { let dTop = floatingLabel.font.lineHeight + floatingLabelBottomMargin newRect = UIEdgeInsetsInsetRect(newRect, UIEdgeInsets(top: dTop, left: 0.0, bottom: 0.0, right: 0.0)) } return newRect } - - override func editingRectForBounds(bounds: CGRect) -> CGRect { + + override public func editingRectForBounds(bounds: CGRect) -> CGRect { return self.textRectForBounds(bounds) } - + // MARK - private private func setFloatingLabelOverlapTextField() { let textRect = self.textRectForBounds(self.bounds) @@ -177,7 +177,7 @@ class MKTextField : UITextField { floatingLabel.frame = CGRect(x: originX, y: padding.height, width: floatingLabel.frame.size.width, height: floatingLabel.frame.size.height) } - + private func showFloatingLabel() { let curFrame = floatingLabel.frame floatingLabel.frame = CGRect(x: curFrame.origin.x, y: self.bounds.height/2, width: curFrame.width, height: curFrame.height) @@ -186,7 +186,7 @@ class MKTextField : UITextField { self.floatingLabel.frame = curFrame }, completion: nil) } - + private func hideFloatingLabel() { floatingLabel.alpha = 0.0 } From 56315b4a364b929619635ce87e8f658336b432a8 Mon Sep 17 00:00:00 2001 From: Ken Tominaga Date: Tue, 17 Feb 2015 12:53:46 +0900 Subject: [PATCH 2/4] Add public modifiers in MKColor --- Source/MKColor.swift | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Source/MKColor.swift b/Source/MKColor.swift index 87c1e7d..46d9e08 100644 --- a/Source/MKColor.swift +++ b/Source/MKColor.swift @@ -9,32 +9,32 @@ import UIKit extension UIColor { - convenience init(hex: Int, alpha: CGFloat = 1.0) { + convenience public init(hex: Int, alpha: CGFloat = 1.0) { let red = CGFloat((hex & 0xFF0000) >> 16) / 255.0 let green = CGFloat((hex & 0xFF00) >> 8) / 255.0 let blue = CGFloat((hex & 0xFF)) / 255.0 self.init(red:red, green:green, blue:blue, alpha:alpha) } - + struct MKColor { - static let Red = UIColor(hex: 0xF44336) - static let Pink = UIColor(hex: 0xE91E63) - static let Purple = UIColor(hex: 0x9C27B0) - static let DeepPurple = UIColor(hex: 0x67AB7) - static let Indigo = UIColor(hex: 0x3F51B5) - static let Blue = UIColor(hex: 0x2196F3) - static let LightBlue = UIColor(hex: 0x03A9F4) - static let Cyan = UIColor(hex: 0x00BCD4) - static let Teal = UIColor(hex: 0x009688) - static let Green = UIColor(hex: 0x4CAF50) - static let LightGreen = UIColor(hex: 0x8BC34A) - static let Lime = UIColor(hex: 0xCDDC39) - static let Yellow = UIColor(hex: 0xFFEB3B) - static let Amber = UIColor(hex: 0xFFC107) - static let Orange = UIColor(hex: 0xFF9800) - static let DeepOrange = UIColor(hex: 0xFF5722) - static let Brown = UIColor(hex: 0x795548) - static let Grey = UIColor(hex: 0x9E9E9E) - static let BlueGrey = UIColor(hex: 0x607D8B) + public static let Red = UIColor(hex: 0xF44336) + public static let Pink = UIColor(hex: 0xE91E63) + public static let Purple = UIColor(hex: 0x9C27B0) + public static let DeepPurple = UIColor(hex: 0x67AB7) + public static let Indigo = UIColor(hex: 0x3F51B5) + public static let Blue = UIColor(hex: 0x2196F3) + public static let LightBlue = UIColor(hex: 0x03A9F4) + public static let Cyan = UIColor(hex: 0x00BCD4) + public static let Teal = UIColor(hex: 0x009688) + public static let Green = UIColor(hex: 0x4CAF50) + public static let LightGreen = UIColor(hex: 0x8BC34A) + public static let Lime = UIColor(hex: 0xCDDC39) + public static let Yellow = UIColor(hex: 0xFFEB3B) + public static let Amber = UIColor(hex: 0xFFC107) + public static let Orange = UIColor(hex: 0xFF9800) + public static let DeepOrange = UIColor(hex: 0xFF5722) + public static let Brown = UIColor(hex: 0x795548) + public static let Grey = UIColor(hex: 0x9E9E9E) + public static let BlueGrey = UIColor(hex: 0x607D8B) } } From 26d42b35589d573328d03eb6704b344e388e75a1 Mon Sep 17 00:00:00 2001 From: Ken Tominaga Date: Tue, 17 Feb 2015 13:09:34 +0900 Subject: [PATCH 3/4] Remove "self." --- Source/MKButton.swift | 6 +++--- Source/MKLayer.swift | 4 ++-- Source/MKTableViewCell.swift | 4 ++-- Source/MKTextField.swift | 36 ++++++++++++++++++------------------ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Source/MKButton.swift b/Source/MKButton.swift index dbbd835..5f38c7c 100644 --- a/Source/MKButton.swift +++ b/Source/MKButton.swift @@ -84,7 +84,7 @@ public class MKButton : UIButton // MARK - setup methods private func setupLayer() { adjustsImageWhenHighlighted = false - self.cornerRadius = 2.5 + cornerRadius = 2.5 mkLayer.setBackgroundLayerColor(backgroundLayerColor) mkLayer.setCircleLayerColor(circleLayerColor) } @@ -105,8 +105,8 @@ public class MKButton : UIButton // shadow animation for self if shadowAniEnabled { - let shadowRadius = self.layer.shadowRadius - let shadowOpacity = self.layer.shadowOpacity + let shadowRadius = layer.shadowRadius + let shadowOpacity = layer.shadowOpacity //if mkType == .Flat { // mkLayer.animateMaskLayerShadow() diff --git a/Source/MKLayer.swift b/Source/MKLayer.swift index 5816a50..2944369 100644 --- a/Source/MKLayer.swift +++ b/Source/MKLayer.swift @@ -15,7 +15,7 @@ public enum MKTimingFunction { case EaseOut case Custom(Float, Float, Float, Float) - public var function : CAMediaTimingFunction { + public var function: CAMediaTimingFunction { switch self { case .Linear: return CAMediaTimingFunction(name: "linear") @@ -123,7 +123,7 @@ public class MKLayer { public func didChangeTapLocation(location: CGPoint) { if rippleLocation == .TapLocation { - self.setCircleLayerLocationAt(location) + setCircleLayerLocationAt(location) } } diff --git a/Source/MKTableViewCell.swift b/Source/MKTableViewCell.swift index 17c8f22..d7bbe1e 100644 --- a/Source/MKTableViewCell.swift +++ b/Source/MKTableViewCell.swift @@ -49,7 +49,7 @@ public class MKTableViewCell : UITableViewCell { } private func setupLayer() { - self.selectionStyle = .None + selectionStyle = .None mkLayer.setBackgroundLayerColor(backgroundLayerColor) mkLayer.setCircleLayerColor(circleLayerColor) mkLayer.circleGrowRatioMax = 1.2 @@ -63,7 +63,7 @@ public class MKTableViewCell : UITableViewCell { mkLayer.superLayerDidResize() contentViewResized = true } - mkLayer.didChangeTapLocation(firstTouch.locationInView(self.contentView)) + mkLayer.didChangeTapLocation(firstTouch.locationInView(contentView)) mkLayer.animateScaleForCircleLayer(0.65, toScale: 1.0, timingFunction: circleAniTimingFunction, duration: CFTimeInterval(circleAniDuration)) mkLayer.animateAlphaForBackgroundLayer(MKTimingFunction.Linear, duration: CFTimeInterval(backgroundAniDuration)) diff --git a/Source/MKTextField.swift b/Source/MKTextField.swift index 746aae2..f517ca7 100644 --- a/Source/MKTextField.swift +++ b/Source/MKTextField.swift @@ -60,9 +60,9 @@ public class MKTextField : UITextField { bottomBorderLayer = nil if bottomBorderEnabled { bottomBorderLayer = CALayer() - bottomBorderLayer?.frame = CGRect(x: 0, y: self.layer.bounds.height - 1, width: self.bounds.width, height: 1) + bottomBorderLayer?.frame = CGRect(x: 0, y: layer.bounds.height - 1, width: bounds.width, height: 1) bottomBorderLayer?.backgroundColor = UIColor.MKColor.Grey.CGColor - self.layer.addSublayer(bottomBorderLayer) + layer.addSublayer(bottomBorderLayer) } } } @@ -98,9 +98,9 @@ public class MKTextField : UITextField { } private func setupLayer() { - self.cornerRadius = 2.5 - self.layer.borderWidth = 1.0 - self.borderStyle = .None + cornerRadius = 2.5 + layer.borderWidth = 1.0 + borderStyle = .None mkLayer.circleGrowRatioMax = 1.0 mkLayer.setBackgroundLayerColor(backgroundLayerColor) mkLayer.setCircleLayerColor(circleLayerColor) @@ -109,7 +109,7 @@ public class MKTextField : UITextField { floatingLabel = UILabel() floatingLabel.font = floatingLabelFont floatingLabel.alpha = 0.0 - self.addSubview(floatingLabel) + addSubview(floatingLabel) } override public func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent) -> Bool { @@ -128,18 +128,18 @@ public class MKTextField : UITextField { return } - if !self.text.isEmpty { - floatingLabel.textColor = self.isFirstResponder() ? self.tintColor : floatingLabelTextColor + if !text.isEmpty { + floatingLabel.textColor = isFirstResponder() ? tintColor : floatingLabelTextColor if floatingLabel.alpha == 0 { - self.showFloatingLabel() + showFloatingLabel() } } else { - self.hideFloatingLabel() + hideFloatingLabel() } - bottomBorderLayer?.backgroundColor = self.isFirstResponder() ? self.tintColor.CGColor : bottomBorderColor.CGColor - let borderWidth = self.isFirstResponder() ? bottomBorderHighlightWidth : bottomBorderWidth - bottomBorderLayer?.frame = CGRect(x: 0, y: self.layer.bounds.height - borderWidth, width: self.layer.bounds.width, height: borderWidth) + bottomBorderLayer?.backgroundColor = isFirstResponder() ? tintColor.CGColor : bottomBorderColor.CGColor + let borderWidth = isFirstResponder() ? bottomBorderHighlightWidth : bottomBorderWidth + bottomBorderLayer?.frame = CGRect(x: 0, y: layer.bounds.height - borderWidth, width: layer.bounds.width, height: borderWidth) } override public func textRectForBounds(bounds: CGRect) -> CGRect { @@ -151,7 +151,7 @@ public class MKTextField : UITextField { return newRect } - if !self.text.isEmpty { + if !text.isEmpty { let dTop = floatingLabel.font.lineHeight + floatingLabelBottomMargin newRect = UIEdgeInsetsInsetRect(newRect, UIEdgeInsets(top: dTop, left: 0.0, bottom: 0.0, right: 0.0)) } @@ -159,14 +159,14 @@ public class MKTextField : UITextField { } override public func editingRectForBounds(bounds: CGRect) -> CGRect { - return self.textRectForBounds(bounds) + return textRectForBounds(bounds) } // MARK - private private func setFloatingLabelOverlapTextField() { - let textRect = self.textRectForBounds(self.bounds) + let textRect = textRectForBounds(bounds) var originX = textRect.origin.x - switch self.textAlignment { + switch textAlignment { case .Center: originX += textRect.size.width/2 - floatingLabel.bounds.width/2 case .Right: @@ -180,7 +180,7 @@ public class MKTextField : UITextField { private func showFloatingLabel() { let curFrame = floatingLabel.frame - floatingLabel.frame = CGRect(x: curFrame.origin.x, y: self.bounds.height/2, width: curFrame.width, height: curFrame.height) + floatingLabel.frame = CGRect(x: curFrame.origin.x, y: bounds.height/2, width: curFrame.width, height: curFrame.height) UIView.animateWithDuration(0.45, delay: 0.0, options: .CurveEaseOut, animations: { self.floatingLabel.alpha = 1.0 self.floatingLabel.frame = curFrame From 6c75a75b2bf947267757e9d18b6286981cb96ccc Mon Sep 17 00:00:00 2001 From: Ken Tominaga Date: Tue, 17 Feb 2015 13:36:14 +0900 Subject: [PATCH 4/4] Add missing "public" --- Source/MKButton.swift | 2 +- Source/MKColor.swift | 2 +- Source/MKImageView.swift | 2 +- Source/MKTextField.swift | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/MKButton.swift b/Source/MKButton.swift index 5f38c7c..e7cf251 100644 --- a/Source/MKButton.swift +++ b/Source/MKButton.swift @@ -90,7 +90,7 @@ public class MKButton : UIButton } // MARK - location tracking methods - override func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent) -> Bool { + override public func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent) -> Bool { if rippleLocation == .TapLocation { mkLayer.didChangeTapLocation(touch.locationInView(self)) } diff --git a/Source/MKColor.swift b/Source/MKColor.swift index 46d9e08..a5aed2d 100644 --- a/Source/MKColor.swift +++ b/Source/MKColor.swift @@ -16,7 +16,7 @@ extension UIColor { self.init(red:red, green:green, blue:blue, alpha:alpha) } - struct MKColor { + public struct MKColor { public static let Red = UIColor(hex: 0xF44336) public static let Pink = UIColor(hex: 0xE91E63) public static let Purple = UIColor(hex: 0x9C27B0) diff --git a/Source/MKImageView.swift b/Source/MKImageView.swift index 4c1bdbb..732b1c7 100644 --- a/Source/MKImageView.swift +++ b/Source/MKImageView.swift @@ -103,7 +103,7 @@ public class MKImageView: UIImageView mkLayer.animateAlphaForBackgroundLayer(backgroundAniTimingFunction, duration: CFTimeInterval(aniDuration)) } - override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { + override public func touchesBegan(touches: NSSet, withEvent event: UIEvent) { super.touchesBegan(touches, withEvent: event) if let firstTouch = touches.anyObject() as? UITouch { let location = firstTouch.locationInView(self) diff --git a/Source/MKTextField.swift b/Source/MKTextField.swift index f517ca7..298e8dd 100644 --- a/Source/MKTextField.swift +++ b/Source/MKTextField.swift @@ -121,7 +121,7 @@ public class MKTextField : UITextField { return super.beginTrackingWithTouch(touch, withEvent: event) } - override func layoutSubviews() { + override public func layoutSubviews() { super.layoutSubviews() if !floatingPlaceholderEnabled {