はじめに
Viewの背景に色をつける方法は様々あります。
ただ、どれがベストな方法かわからないのでコメントで教えていただきたいです
作りたいUI
実装
良さそう
Text("テキスト")
.frame(width: 120, height: 60)
.background(Color.cyan, in: RoundedRectangle(cornerRadius: 10))
これも良さそう
Text("テキスト")
.frame(width: 120, height: 60)
.background(Color.cyan)
.cornerRadius(10)
たぶん良くない
ZStack {
RoundedRectangle(cornerRadius: 10)
.frame(width: 120, height: 60)
.foregroundStyle(.cyan)
Text("テキスト")
}
これも良くさなそう
RoundedRectangle(cornerRadius: 10)
.frame(width: 120, height: 60)
.foregroundStyle(.cyan)
.overlay(Text("テキスト"))
おわり
これは好き嫌いの問題?