Material design components for SwiftUI.
- macOS 10.15+
- iOS 13+
- watchOS 6+
tvOS 13+(see issue #1)
Before we begin, note that this project is in the very early stages, and some stuff will probably change. Please feel free to file Issues and Pull Requests.
- From within your app project in Xcode 11 or newer, choose File -> Swift Packages -> Add Package Dependency
- Paste the URL of this GitHub repository
- Click through the remaining steps, choosing which version of MaterialUI you want to track and which targets to add it to
- See the next section to start styling your views!
There are 3 styles of material buttons:
The button style is selected with the buttonStyle
modifier, which may be used on any view to specify the style used for all buttons in that subview hierarchy.
Button("Contained Button", action: {})
.buttonStyle(ContainedButtonStyle())
Button("Outlined Button", action: {})
.buttonStyle(OutlinedButtonStyle())
Button("Text Button", action: {})
.buttonStyle(TextButtonStyle())
In iOS and WatchOS, you can set the color through the accentColor modifier
Button("Contained Button", action: {})
.buttonStyle(ContainedButtonStyle())
.accentColor(Color.green)
In MacOS the accentColor modifier is not available, so you can use the materialAccent environment variable (in fact, you can use this on any platform)
Button("Contained Button", action: {})
.buttonStyle(ContainedButtonStyle())
.environment(\.materialAccent, Color.red)
MaterialUI also supplies some modifiers you can apply to any SwiftUI View:
- elevation
- rippleEffect
TODO: Document these.
To build MaterialUI, simply run swift build
.
If you are on Mac and prefer to hack in Xcode, you can generate an Xcode project with swift package generate-xcodeproj
.
To deal with cases where the SwiftUI implementation varies by platform, the following can be defined at build time to indicate what APIs are available:
HAVE_HOVER
- Enables handling of hover events using theonHover
modifier.HAVE_DRAG
- Enables handling of mouse down location usingDragGesture
.
See Package.swift
for the configurations where these are defined.