Skip to content

Commit

Permalink
Merge pull request #13 from ken0nek/ken0nek
Browse files Browse the repository at this point in the history
cocoapods support
  • Loading branch information
nghialv committed Feb 17, 2015
2 parents 1c27088 + 6c75a75 commit 9e304d9
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 250 deletions.
62 changes: 31 additions & 31 deletions Source/MKButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,112 +9,112 @@
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
self.cornerRadius = 2.5
cornerRadius = 2.5
mkLayer.setBackgroundLayerColor(backgroundLayerColor)
mkLayer.setCircleLayerColor(circleLayerColor)
}

// 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))
}

// 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
let shadowRadius = layer.shadowRadius
let shadowOpacity = 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)
}
}
44 changes: 22 additions & 22 deletions Source/MKColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 struct MKColor {
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)
}
}
58 changes: 29 additions & 29 deletions Source/MKImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,101 +9,101 @@
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) {

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)
Expand Down
Loading

0 comments on commit 9e304d9

Please sign in to comment.