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?

【Swift】glassEffect の第二引数にshapeを渡せることを知った

0
Posted at

随分と困ってたんですが、参考になる記事と巡り会えたので備忘録としてまとめます。

困ってたこと

角丸長方形のviewの背景にglassEffectを指定していたが、glassEffectの角丸度合いとviewの角丸度合いがずれてしまい、効果が適用されない範囲が生まれていた

対処方法

.glassEffect(.clear.tint(.white.opacity(0.4)), in: RoundedRectangle(cornerRadius: 12))

ポイント

よく定義を読むと、第二引数(in)にはshapeを渡せる様になっている。

nonisolated public func glassEffect(_ glass: Glass = .regular, in shape: some Shape = DefaultGlassEffectShape()) -> some View

デフォルトでは「DefaultGlassEffectShape」になるということで、独特の角丸長方形というか楕円というかそんな形が適用される模様。

この第二引数に任意のshapeを渡せば、その形に即した描画が走る。
(Rectangle() と指定したら角丸をなくすことができる)

参考

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?