iOS animation playback button inspired by the playback button of YouTube for web.
##Installation
####CocoaPods
pod 'PlaybackButton'
####Manually
Add the PlaybackButton.swift
file to your project.
##Usage
###Setup
Add import PlaybackButton
in your file
In your app delegate:
@IBOutlet weak var playbackButton: PlaybackButton!
self.playbackButton.layer.cornerRadius = self.playbackButton.frame.size.height / 2
self.playbackButton.layer.borderWidth = 2.0
self.playbackButton.adjustMargin = 1
@IBAction func didTapPlaybackButton(sender: AnyObject) {
if self.playbackButton.buttonState == .Playing {
self.playbackButton.setButtonState(.Pausing, animated: true)
} else if self.playbackButton.buttonState == .Pausing {
self.playbackButton.setButtonState(.Playing, animated: true)
}
}
var playbackButton: PlaybackButton!
self.playbackButton = PlaybackButton(frame: CGRect(x: 0, y:20, width: 100, height: 100 ))
self.playbackButton.contentEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
self.playbackButton.adjustMargin = 0
self.playbackButton.addTarget(self, action: "didTapPlaybackButton:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(self.playbackButton)
func didTapPlaybackButton(sender: AnyObject) {
if self.playbackButton.buttonState == .Playing {
self.playbackButton.setButtonState(.Pausing, animated: true)
} else if self.playbackButton.buttonState == .Pausing {
self.playbackButton.setButtonState(.Playing, animated: true)
}
}
Requires Swift2.0 and iOS 8.0 and ARC.
If you want to use even iOS7.0, please to import the code directly.
- Highly customizable
- Complete example
Forks, patches and other feedback are welcome.
PlaybackButton is available under the MIT license. See the LICENSE file for more info.