๐ SwiftUI LoadingButton ๐
Simple Loading Animation Button for SwiftUI
๐น 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/LoadingButton", from: "1.1.2")
๐Usage
LoadingButton(action: { }, isLoading: <Binding>Bool, style: LoadingButtonStyle) {
// View on the button
// style is optional parameter
action
: Actions to do when button clickedisLoading
:<Binding>Bool
type. you can control loading status with this.style
(Optional) : Custom style withLoadingButtonStyle
๐ Custom Modifiers
LoadingButtonStyle(width: CGFloat,
height: CGFloat,
cornerRadius: CGFloat,
backgroundColor: Color,
loadingColor: Color,
strokeWidth: CGFloat,
strokeColor: Color)
// All of the parameter is optional
width
(Optional) : Width of buttonheight
(Optional) : Height of buttoncornerRadius
(Optional) : Corner radius of buttonbackgroundColor
(Optional) : Background color of buttonloadingColor
(Optional) : Background color of button whenLoading
, default is 50% opacity ofbackgroundColor
strokeWidth
(Optional) : Circle loading indicator stroke widthstrokeColor
(Optional) : Circle loading indicator stroke Color(default: gray)
Example
๐ถ Simple
import SwiftUI
import LoadingButton
struct ContentView: View {
@State var isLoading: Bool = false
var body: some View {
LoadingButton(action: {
// Your Action here
}, isLoading: $isLoading) {
Text("LoadingButton").foregroundColor(Color.white)
}
}
}
Result
๐ ๐ป Applying Fully Custom Style
import SwiftUI
import LoadingButton
struct ContentView: View {
@State var isLoading: Bool = false
var style = LoadingButtonStyle(width: 312,
height: 54,
cornerRadius: 27,
backgroundColor: .orange,
loadingColor: Color.orange.opacity(0.5),
strokeWidth: 5,
strokeColor: .gray)
var body: some View {
LoadingButton(action: {
// Your Action here
}, isLoading: $isLoading, style: style) {
Text("Styled LoadingButton").foregroundColor(Color.white)
}
}
}
Result
๐ ๐ป Styling Only Needs
import SwiftUI
import LoadingButton
struct ContentView: View {
@State var isLoading: Bool = false
var body: some View {
LoadingButton(action: {
// Your Action here
}, isLoading: $isLoading, style: LoadingButtonStyle(cornerRadius: 27, backgroundColor: .orange)) {
Text("Styled LoadingButton").foregroundColor(Color.white)
}
}
}
Same Result
โ TODO
- End animation(normal, shake(when fail), expand)
- Support gradient background color
๐ License
LoadingButton is available under the MIT license. See the LICENSE
file for more info.
โ๏ธ Author
- Byun Kyung Min โ ๐ฐ๐ท@Changemin