Swiftpack.co - Package - Changemin/PressableButton

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

Changemin/PressableButton

๐Ÿ•นPressing Animation & Haptic Feedback Button for SwiftUI๐Ÿ•น

Project logo

๐Ÿ•น SwiftUI Pressable Button ๐Ÿ•น

License Release


๐Ÿ“น Preview

๐Ÿ Getting Started

Requirements

  • Xcode 11+
  • SwiftUI
  • iOS 14+
  • macOS 10.15+

Installaion

Swift Package Manager(SPM)

File โžœ Swift Packages โžœ Add Package Dependancy..
.package(url: "https://github.com/Changemin/PressableButton", from: "1.1.0")

๐ŸŽˆUsage

PressableButton(action: { YOUR ACTION }) {
    // YOUR VIEW
}
  • action : Functions to execute

๐Ÿ› Custom Modifiers

PressableButton(action: { YOUR ACTION }) {
    // YOUR VIEW
}.accentColor(_ color: color)
.cornerRadius(_ amount: CGFloat)
.frame(width: CGFloat, height: CGFloat)
.enableHaptic(intensity: UIImpactFeedbackGenerator.FeedbackStyle)
.disableHaptic()
  • .accentColor() : Accent color
  • .cornerRadius() : Corner Radius of the button
  • .frame() : Size of the button
  • .enableHaptic() : Enable haptic effect with insensity(.heavy, .medium, .light, .rigid, .soft)
  • .disableHaptic() : Disable haptic effect

Example

๐Ÿ‘ถ Simple

import PressableButton

struct ContentView: View {
    var body: some View {
        PressableButton(action: {
            print("Button pressed")
        }) {
            Text("Simple Example").foregroundColor(.white)
        }
    }
}

Result

๐Ÿ›  Custom Modifiers

import PressableButton

struct ContentView: View {
    var body: some View {
        PressableButton(action: {
            print("Button pressed")
        }) {
            Text("PUSH ME !").foregroundColor(.white)
        }
        .enableHaptic(.soft)
        .accentColor(.orange)
        .cornerRadius(0)
    }
}

Result

โœ… TODO

  • โ˜ support variable styles FlatStyle, PushButtonStyle, etc
  • โ˜‘ add haptic feedback

๐Ÿ“œ License

PressableButton is available under the MIT license. See the LICENSE file for more info.

โœ๏ธ Author

Github

link
Stars: 3
Last commit: 1 week ago

Releases

Version 1.2.0 - 2021-01-29T15:12:30