Skip to content

atrinh0/buttoncraft

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
August 15, 2020 15:09
August 2, 2020 15:13
September 12, 2020 15:52

buttoncraft (SwiftUI App)

Experimenting with SwiftUI whilst creating a practical app to craft that perfect button style.

✈️ Testflight

https://testflight.apple.com/join/pZDhygQt

Last TestFlight bump: 28th July 2023

πŸ‘¨πŸ»β€πŸ’» Code outputted from app

struct MyButtonStyle: ButtonStyle {
    func makeBody(configuration: Self.Configuration) -> some View {
        configuration.label
            .background(Capsule()
                            .foregroundColor(configuration.isPressed ? Color.primary.opacity(0.75) : Color.primary))
            .scaleEffect(configuration.isPressed ? CGFloat(0.85) : 1.0)
            .rotationEffect(.degrees(configuration.isPressed ? 0.0 : 0))
            .blur(radius: configuration.isPressed ? CGFloat(0.0) : 0)
            .animation(Animation.spring(response: 0.35, dampingFraction: 0.35, blendDuration: 1), value: configuration.isPressed)
    }
}

extension Button {
    func myButtonStyle() -> some View {
        self.buttonStyle(MyButtonStyle())
    }
}

// to use
Button { } label: {
    Text("just like that")
        .font(Font.body.bold())
        .padding()
        .foregroundColor(Color.primary)
        .colorInvert()
}
.myButtonStyle()

Button { } label: {
    Image(systemName: "face.smiling")
        .font(Font.body.bold())
        .imageScale(.large)
        .padding()
        .foregroundColor(Color.primary)
        .colorInvert()
}
.myButtonStyle()

🧐 Features

  • πŸ”€ Randomise different settings for inspiration
  • Reset to my default style
  • Using the new iOS ColorPicker
  • Copy your perfect masterpiece as a code snippet to your clipboard

πŸ‘¨πŸ»β€βš–οΈ Disclaimer

This is posted as a way to share SwiftUI learnings (and is not production level code). Use it at your own risk.

About

Craft that perfect SwiftUI button effect πŸ‘ŒπŸΌ

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages