2
0

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 1 year has passed since last update.

【visionOS】Buttonの標準の背景色を透明にする

Last updated at Posted at 2024-05-08

本記事では、visionOSでButtonの標準背景色を透明にし、背景色をカスタマイズする方法について説明します。

(※技適特例届け出済み)

問題

Buttonに.background(Color.clear)を指定しても、楕円形の背景色が残ってしまいます。

Button(action: { }) {
   ZStack {
       Circle()
           .frame(width: 60, height: 60)
           .foregroundStyle(.gray)
       Image(systemName: "square.and.arrow.up")
           .resizable()
           .aspectRatio(contentMode: .fit)
           .frame(width: 22)
   }
}
.background(Color.clear)
ファイル名

解決方法

この問題は、以下のように.buttonStyle(.plain)を指定することで解決できます。

Button(action: { }) {
    ZStack {
        Circle()
            .frame(width: 60, height: 60)
            .foregroundStyle(.gray)
        Image(systemName: "square.and.arrow.up")
            .resizable()
            .aspectRatio(contentMode: .fit)
            .frame(width: 22)
    }
}
.buttonStyle(.plain)
ファイル名

.buttonStyle(.plain)を指定することで、標準の背景を削除し、透明な背景を実現できます。これにより、自由にButtonの背景色をカスタマイズすることが可能になります。

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?