The modifier to apply to this view.
Instance Method
インスタンスメソッド
modifier(_:)
Applies a modifier to a view and returns a new view.
Availability 有効性
- iOS 13.0+
- iPadOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
Technology
- Swift
UI
Declaration 宣言
func modifier<T>(_ modifier: T) -> ModifiedContent
<Self, T>
Parameters パラメータ
modifier
Discussion 議論
Use this modifier to combine a View
and a View
, to create a new view. For example, if you create a view modifier for a new kind of caption with blue text surrounded by a rounded rectangle:
struct BorderedCaption: ViewModifier {
func body(content: Content) -> some View {
content
.font(.caption2)
.padding(10)
.overlay(
RoundedRectangle(cornerRadius: 15)
.stroke(lineWidth: 1)
)
.foregroundColor(Color.blue)
}
}
You can use modifier(_:)
to extend View
to create new modifier for applying the Bordered
defined above:
extension View {
func borderedCaption() -> some View {
modifier(BorderedCaption())
}
}
Then you can apply the bordered caption to any view:
Image(systemName: "bus")
.resizable()
.frame(width:50, height:50)
Text("Downtown Bus")
.borderedCaption()