概要
SwiftUIの記述で.clipped
をよく見かけます。
これが何をしてくれるのか分からなかったので調べてみます。
公式より
和訳を添付します。
clipped(antialiased :)修飾子を使用して、シェイプのレイアウト境界を超えて拡張するコンテンツを非表示にします。
デフォルトでは、ビューの境界フレームはレイアウトにのみ使用されるため、フレームの端を超えて拡張されたコンテンツは引き続き表示されます。
.clipped
あるなしで比較する
ある場合

ClippedSample.swift
struct ClippedSample: View {
var body: some View {
Text("This long text string is clipped")
.fixedSize()
.frame(width: 175, height: 100)
.clipped()
.border(Color.gray)
}
}
ない場合

ClippedSample.swift
struct ClippedSample: View {
var body: some View {
Text("This long text string is clipped")
.fixedSize()
.frame(width: 175, height: 100)
// .clipped()
.border(Color.gray)
}
}
フレームを超えるコンテンツを切り取ってくれるみたいです。