https://github.com/samuelbeek/recordbutton
A record button in Swift
https://github.com/samuelbeek/recordbutton
animation button camera recording swift ui
Last synced: 5 months ago
JSON representation
A record button in Swift
- Host: GitHub
- URL: https://github.com/samuelbeek/recordbutton
- Owner: samuelbeek
- License: mit
- Created: 2015-10-07T13:29:30.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-11-10T09:07:58.000Z (almost 5 years ago)
- Last Synced: 2025-04-19T22:02:29.811Z (6 months ago)
- Topics: animation, button, camera, recording, swift, ui
- Language: Swift
- Size: 71.3 KB
- Stars: 129
- Watchers: 6
- Forks: 34
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RecordButton
[](https://travis-ci.org/samuelbeek/RecordButton)
[](http://cocoapods.org/pods/RecordButton)
[](http://cocoapods.org/pods/RecordButton)
[](http://cocoapods.org/pods/RecordButton)A Record Button in Swift. Inspired by [SDRecordButton](https://github.com/sebyddd/SDRecordButton)
It shows you the recording process when recording. It's great for a video recorder app with a fixed/maximum length like snapchat, vine, instragram.
## Requirements
iOS 8 and higher
## Example Project
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Installation
RecordButton is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "RecordButton"
```
Add this line add the top of the file you want to use this module in `import RecordButton`
## Usage
### Add a simple RecordButton
Add this to `viewDidLoad`
```swift
let recordButton = RecordButton(frame: CGRect(x: 0,y: 0,width: 70,height: 70))
view.addSubview(recordButton)```
### Update progress
*it's the easiest to just check out the example project for this.*To update progress the RecordButton must be an instance of the class. You should also add a `progressTimer` and a `progress` variable, like this:
```swift
class ViewController: UIViewController {
var recordButton : RecordButton!
var progressTimer : Timer!
var progress : CGFloat = 0
// rest of viewController
```The `recordButton` needs a target for start and stopping the progress timer. Add this code after initialization of the `recordButton` (usualy in `viewDidLoad()`)
```swift
recordButton.addTarget(self, action: #selector(self.record), for: .touchDown)
recordButton.addTarget(self, action: #selector(self.stop), for: UIControl.Event.touchUpInside)```
Finally add these functions to your ViewController
```swift
@objc func record() {
self.progressTimer = Timer.scheduledTimer(timeInterval: 0.05, target: self, selector: #selector(ViewController.updateProgress), userInfo: nil, repeats: true)
}
@objc func updateProgress() {
let maxDuration = CGFloat(5) // Max duration of the recordButton
progress = progress + (CGFloat(0.05) / maxDuration)
recordButton.setProgress(progress)
if progress >= 1 {
progressTimer.invalidate()
}
}
@objc func stop() {
self.progressTimer.invalidate()
}
```
## Support/Issues
If you have any questions, please don't hesitate to create an issue.## To Do
* Add Carthage Support
* Add a delegation pattern## Author
[samuelbeek](http://twitter.com/samuelbeek) - iOS Developer, Consultant and Occasional Designer
## Acknowledgements
This button is heavely inspired by [SDRecordButton](https://github.com/sebyddd/SDRecordButton), which is made by [Sebyddd](https://github.com/sebyddd)## License
RecordButton is available under the MIT license. See the LICENSE file for more info.