lukluca/radiobutton
`RadioButton` is the missing SwiftUI Radio Button view. It uses the same approach as SwiftUI's `Picker` `radioGroup` style only available on macOS.
π· Requirements
β macOS 10.15+ β Xcode 11.0 β Swift 5+ β iOS 14+ β tvOS 14+ β watchOS 7+
π· Installation
RadioButton is available via Swift Package Manager.
Using Xcode 11, go to File -> Swift Packages -> Add Package Dependency and enter https://github.com/lukluca/RadioButton
or add manually the dependency
dependencies: [
.package(url: "https://github.com/lukluca/RadioButton", from: "1.1.0")
]π· Usage
It's very simple to use RadioButton, expecially with Swift's enum type:
enum City: String, CaseIterable, Identifiable {
case milano
case roma
case palermo
var id: RawValue {
rawValue
}
}
struct ContentView: View {
@State private var city = City.milano
var body: some View {
RadioButton(title: "Cities:",
itemTitle: \.rawValue,
isSelected: $city)
}
}It's a requirement that your model must implement CaseIterable, Hashable and Identifiable protocol.
For furter configurations, please see RadioButtonExample folder, it contains a very simple app with all the possible scenario.
π· Last version
Last version is 1.2.0.
Starting from this version, you can use a vertical or an horizontal alignment.
π· Roadmap / TODOs
Version 1.0.0 of RadioButton contains a very limited set of features, basically no particular feature :smile:.
It could be extended by implementing the following tasks:
βοΈ Add unit/UI tests; βοΈ Make view modifier to set common configuration (font, colors, etc); βοΈ ... many other improvements.
π· Contributing
π¨π»βπ§ Feel free to contribute to RadioButton by creating a pull request, following these guidelines:
- Fork
RadioButton - Create your feature branch
- Commit your changes, along with unit tests
- Push to the branch
- Create pull request
π· License
π RadioButton is available under the MIT license. See the LICENSE file for more info.
[license-url]: LICENSE [user-url]: https://github.com/lukluca [project-url]: https://github.com/lukluca/RadioButton
Package Metadata
Repository: lukluca/radiobutton
Default branch: main
README: README.md