Swift clipShape修飾子を使ってTextの背景色を角丸にするサンプル
環境
Swift version 5.2.3 (swift-5.2.3-RELEASE)
Ubuntu 20.04.2 LTS
構文
Text("xxx")
.background(
color.clipShape(RoundedRectangle(cornerRadius: 角の丸み))
)
Text("xxx")
.background(
color.clipShape(RoundedRectangle(cornerRadius: 角の丸み))
)
Text("xxx") .background( color.clipShape(RoundedRectangle(cornerRadius: 角の丸み)) )
Textにbackground修飾子を付与し、background修飾子の引数に背景色を指定します。
clipShape修飾子の引数にRoundedRectangle()を指定します。
RoundedRectangle()の引数「cornerRadius」に角の丸みを指定します。
使用例
struct ContentView: View {
var body: xxx View {
VStack {
Text("Study, Swift,Skill")
.foregroundColor(.white)
.padding()
.background(
Color.red.clipShape(RoundedRectangle(cornerRadius: 13))
)
}
}
}
struct ContentView: View {
var body: xxx View {
VStack {
Text("Study, Swift,Skill")
.foregroundColor(.white)
.padding()
.background(
Color.red.clipShape(RoundedRectangle(cornerRadius: 13))
)
}
}
}
struct ContentView: View { var body: xxx View { VStack { Text("Study, Swift,Skill") .foregroundColor(.white) .padding() .background( Color.red.clipShape(RoundedRectangle(cornerRadius: 13)) ) } } }