1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【SwiftUI】Toggleのあるセルを行全体タップで値を切り替える方法

Posted at

こうする

@State var isOn = false
~~~
 
    Toggle(isOn: $isOn, label: {
        Text("Toggle Test")
    })
    .contentShape(Rectangle())
    .onTapGesture {
        self.isOn.toggle()
    }

.contentShape(Rectangle()).onTapGesture を一緒に書くことで、
行全体タップしたときに、Toggleの値を切り替えることができる。
行の中の空白部分をタップしてもイベントを拾うようになる。

環境

  • Xcode 15.4

参考

1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?