Skip to content

Commit

Permalink
[clean]code.
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki_keishi committed Jan 4, 2016
1 parent 715551d commit 7b9f6aa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
29 changes: 22 additions & 7 deletions AnimatablePlayButton/AnimatablePlayButton.swift
Expand Up @@ -2,13 +2,12 @@
// AnimatablePlayButton.swift
// AnimatablePlayButton
//
// Created by 鈴木 啓司 on 2015/12/01.
// Copyright © 2015年 suzuki_keishi. All rights reserved.
// Created by suzuki keishi on 2015/12/01.
// Copyright © 2015 suzuki_keishi. All rights reserved.
//

import UIKit

@IBDesignable
public class AnimatablePlayButton: UIButton {

public var color: UIColor! = .whiteColor() {
Expand Down Expand Up @@ -45,21 +44,36 @@ public class AnimatablePlayButton: UIButton {

public override func awakeFromNib() {
super.awakeFromNib()
setup()
createLayers(frame)
clipsToBounds = true
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
createLayers(frame)
clipsToBounds = true
}

override public required init(frame: CGRect) {
super.init(frame: frame)
setup()
createLayers(frame)
clipsToBounds = true
}

convenience public init(origin: CGPoint, lengthOfSize: CGFloat){
self.init(frame: CGRectMake(origin.x, origin.y, lengthOfSize, lengthOfSize))
}

convenience public init(lengthOfSize: CGFloat){
self.init(frame: CGRectMake(0, 0, lengthOfSize, lengthOfSize))
}

// MARK: - private
private func setup(){
clipsToBounds = true
bgColor = .blackColor()
color = .whiteColor()
}

private func createLayers(frame: CGRect) {

Expand Down Expand Up @@ -202,7 +216,8 @@ public class AnimatablePlayButton: UIButton {
animation.removedOnCompletion = false
animation.fillMode = kCAFillModeForwards
}


// MARK: - public
public func select() {
selected = true

Expand Down
Expand Up @@ -16,9 +16,9 @@ class ViewController: UIViewController {

view.backgroundColor = .blackColor()

let button = AnimatablePlayButton(frame: CGRectMake(0, 0, 120, 120))
let button = AnimatablePlayButton(lengthOfSize: 120)
button.center = CGPointMake(CGRectGetMidX(view.frame), CGRectGetMidY(view.frame))
button.bgColor = .blackColor()
button.bgColor = .blackColor()
button.color = .whiteColor()
button.addTarget(self, action: Selector("tapped:"), forControlEvents: UIControlEvents.TouchUpInside)

Expand Down
29 changes: 20 additions & 9 deletions README.md
@@ -1,31 +1,41 @@
# AnimatablePlayButton

Animated Button written in Swift2.0, using CALayer.
Animated Button written in Swift2.0, using CALayer, CAKeyframeAnimation.

![sample](Screenshots/example01.gif)

## features
- Only using CAShapeLayer, no image.
- Only using CAShapeLayer, CAKeyframeAnimation. not from image object.

## Requirements
- iOS 8.0+
- Swift 2.0+
- ARC

## Installation
#### Carthage
TODO
##Installation

#### CocoaPods
TODO
####CocoaPods
available on CocoaPods. Just add the following to your project Podfile:
```
pod 'AnimatablePlayButton'
use_frameworks!
```

####Carthage
To integrate into your Xcode project using Carthage, specify it in your Cartfile:

```ogdl
github "suzuki-0000/AnimatablePlayButton"
```

## How to use
See the code snippet below for an example of how to implement, or example project would be easy to understand.
See the code snippet below for an example of how to implement.
example project would be easy to understand.

#### 1. Create a button, specify backgroundColor of Button(bgColor), and button color(color).
```swift
let button = AnimatablePlayButton(frame: CGRectMake(0, 0, 44, 44))
button.bgColor = UIColor(red: 38.0 / 255, green: 151.0 / 255, blue: 68.0 / 255, alpha: 1)
button.bgColor = .blackColor()
button.color = .whiteColor()
self.view.addSubview(button)
```
Expand All @@ -46,3 +56,4 @@ func tapped(sender: AnimatablePlayButton) {

## License
available under the MIT license. See the LICENSE file for more info.

0 comments on commit 7b9f6aa

Please sign in to comment.