https://github.com/erikdrobne/camerabutton
A simple camera button that can be used for photo and video capturing.
https://github.com/erikdrobne/camerabutton
button ios swift swiftui ui xcode
Last synced: 12 months ago
JSON representation
A simple camera button that can be used for photo and video capturing.
- Host: GitHub
- URL: https://github.com/erikdrobne/camerabutton
- Owner: erikdrobne
- License: mit
- Created: 2022-01-20T09:46:36.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-08-31T13:35:03.000Z (over 2 years ago)
- Last Synced: 2025-03-23T10:44:15.994Z (12 months ago)
- Topics: button, ios, swift, swiftui, ui, xcode
- Language: Swift
- Homepage:
- Size: 39.1 KB
- Stars: 22
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CameraButton


A simple camera button that can be used for photo and video capturing.
## Requirements
**iOS 14.0** or higher
## Instalation
### Swift Package Manager
```Swift
dependencies: [
.package(url: "https://github.com/erikdrobne/CameraButton")
]
```
## Usage
### Import
```Swift
import CameraButton
```
### UIKit
### Initialize
```Swift
let button = CameraButton()
button.delegate = self
view.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
button.widthAnchor.constraint(equalToConstant: 72),
button.heightAnchor.constraint(equalToConstant: 72),
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -64)
])
```
### Customize
```Swift
// Set custom colors
button.borderColor = .red
button.fillColor = (.purple, .orange)
button.progressColor = .green
// Set progress animation duration
button.progressDuration = 5
// Start progress animation
button.start()
// Stop progress animation
button.stop()
```
### Delegate
The `CameraButtonDelegate` requires you to implement the following methods:
```Swift
func didTap(_ button: CameraButton)
func didFinishProgress()
```
### SwiftUI
```Swift
struct PhotoView: View {
@State var isRecording: Bool = false
@State var didFinishProgress: Bool = false
var body: some View {
CameraButtonUI(
size: 72,
borderColor: .red,
fillColor: (.purple, .orange),
progressColor: .green,
progressDuration: 5,
isRecording: self.$isRecording
)
// Handle tap gesture
.simultaneousGesture(
TapGesture()
.onEnded { _ in
print("tap")
}
)
// Start recording on Long-press gesture
.gesture(
LongPressGesture(minimumDuration: 1)
.onChanged { val in
isRecording = true
}
)
// Observe state changes
.onChange(of: isRecording, perform: { [isRecording] newValue in
print("isRecording", isRecording, newValue)
})
}
}
```