0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SwiftUIの.clippedは何をしている??

Posted at

概要

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)
    }
}

フレームを超えるコンテンツを切り取ってくれるみたいです。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?