Material
A background material type.
Declaration
type Material =
| 'bar'
| 'regular'
| 'regularMaterial'
| 'thick'
| 'thickMaterial'
| 'thin'
| 'thinMaterial'
| 'ultraThick'
| 'ultraThickMaterial'
| 'ultraThin'
| 'ultraThinMaterial';struct MaterialPass a literal, or build one with SwiftUI.Material from import { SwiftUI } from 'swiftui-react-native'.
Type properties
'bar'SwiftUI.Material.barA material matching the style of system toolbars.
'regular'SwiftUI.Material.regularA material that's somewhat translucent.
'regularMaterial'SwiftUI.Material.regularMaterial'thick'SwiftUI.Material.thickA material that's more opaque than translucent.
'thickMaterial'SwiftUI.Material.thickMaterial'thin'SwiftUI.Material.thinA material that's more translucent than opaque.
'thinMaterial'SwiftUI.Material.thinMaterial'ultraThick'SwiftUI.Material.ultraThickA mostly opaque material.
'ultraThickMaterial'SwiftUI.Material.ultraThickMaterial'ultraThin'SwiftUI.Material.ultraThinA mostly translucent material.
'ultraThinMaterial'SwiftUI.Material.ultraThinMaterial
Overview
You can apply a blur effect to a view that appears behind another view by
adding a material with the View.background(_:ignoresSafeAreaEdges:)
modifier:
ZStack {
Color.teal
Label("Flag", systemImage: "flag.fill")
.padding()
.background(.regularMaterial)
}In the example above, the ZStack layers a Label on top of the color
ShapeStyle.teal. The background modifier inserts the
regular material below the label, blurring the part of
the background that the label --- including its padding --- covers:
A material isn't a view, but adding a material is like inserting a translucent layer between the modified view and its background:
The blurring effect provided by the material isn't simple opacity. Instead, it uses a platform-specific blending that produces an effect that resembles heavily frosted glass. You can see this more easily with a complex background, like an image:
ZStack {
Image("chili_peppers")
.resizable()
.aspectRatio(contentMode: .fit)
Label("Flag", systemImage: "flag.fill")
.padding()
.background(.regularMaterial)
}For physical materials, the degree to which the background colors pass through depends on the thickness. The effect also varies with light and dark appearance:
If you need a material to have a particular shape, you can use the
View.background(_:in:fillStyle:) modifier. For example, you can
create a material with rounded corners:
ZStack {
Color.teal
Label("Flag", systemImage: "flag.fill")
.padding()
.background(.regularMaterial, in: RoundedRectangle(cornerRadius: 8))
}When you add a material, foreground elements exhibit vibrancy,
a context-specific blend of the foreground and background colors
that improves contrast. However using View.foregroundStyle(_:)
to set a custom foreground style --- excluding the hierarchical styles,
like ShapeStyle.secondary-swift.type.property --- disables vibrancy.
what appears behind your app on the screen. For example, the content on the Home Screen doesn't affect the appearance of a widget.
From Apple’s SwiftUI documentation. Code samples there are Swift.
See also
More in Drawing and shapes.
- AngleA geometric angle whose value you access in either radians or degrees.
- AngularGradientAn angular gradient.
- AnyGradientA color gradient.
- BlendModeModes for compositing a view with overlapping content.
- ButtonBorderShapeA shape used to draw a button's border.
- ColorMatrixA matrix to use in an RGBA color transformation.
- ConcentricRectangleAnimatableDataThe type defining the data to animate.
- ContainerRelativeShapeA shape that is replaced by an inset version of the current container shape. If no container shape was defined, is replaced by a rectangle.
- ContentShapeKindsA kind for the content shape of a view.
- CoordinateSpaceProtocolA frame of reference within the layout system.
- DefaultGlassEffectShapeThe default shape applied by glass effects, a capsule.
- EllipticalGradientA radial gradient that draws an ellipse.