Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SwiftUI
- struct RecordButtons: View {
- var body: some View {
- ZStack {
- Color.gray
- HStack {
- NaiveButton()
- RecordButton()
- PhotoButton()
- }
- }
- }
- }
- struct NaiveButton: View {
- @State var isRecording = false
- var body: some View {
- Circle()
- .strokeBorder(Color.white, lineWidth: 4.0)
- .frame(width: 70, height: 70)
- .overlay(
- RoundedRectangle(cornerRadius: isRecording ? 10: 50)
- .fill(Color.red)
- .scaleEffect(isRecording ? 0.40: 1)
- .frame(width: 58, height: 58)
- .onTapGesture {
- withAnimation {
- isRecording.toggle()
- }
- }
- )
- .frame(width: 70, height: 70)
- }
- }
- struct RecordButton: View {
- @State var isRecording = false
- var body: some View {
- Button("", action: {
- withAnimation {
- isRecording.toggle()
- }
- })
- .buttonStyle(RecordButtonStyle(isRecording: $isRecording))
- .frame(width: 70, height: 70)
- }
- }
- struct PhotoButton: View {
- var body: some View {
- Button("", action: {})
- .buttonStyle(PhotoButtonStyle())
- .frame(width: 70, height: 70)
- }
- }
- struct RecordButtonStyle: ButtonStyle {
- @Binding var isRecording: Bool
- func makeBody(configuration: Configuration) -> some View {
- configuration.label
- .background(
- Circle()
- .strokeBorder(Color.white, lineWidth: 4.0)
- .frame(width: 70, height: 70)
- .overlay(
- RoundedRectangle(cornerRadius: isRecording ? 10: 50)
- .fill(Color.red)
- .scaleEffect(isRecording ? 0.40: 1)
- .frame(width: 58, height: 58)
- )
- )
- }
- }
- struct PhotoButtonStyle: ButtonStyle {
- func makeBody(configuration: Configuration) -> some View {
- configuration.label
- .background(
- Circle()
- .strokeBorder(Color.white, lineWidth: 4.0)
- .frame(width: 70, height: 70)
- .overlay(
- Circle()
- .fill(Color.white)
- .scaleEffect(configuration.isPressed ? 0.95: 1)
- .frame(width: 58, height: 58)
- )
- )
- }
- }
- struct RecordButtons_Previews: PreviewProvider {
- static var previews: some View {
- RecordButtons()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment