どうも、ちょげ(@chogetarou)です。
Buttonの背景をグラデーションにする方法を紹介します。
方法
Buttonの背景をグラデーションにするには、background修飾子を使います。
まず、Buttonにbackground修飾子を付与します。
そして、background修飾子の引数にグラデーションを指定します。
Button(・・・)
.background(LinearGradient(・・・))
引数にグラデーションを指定したbackground修飾子をButtonに付与することで、Buttonの背景をグラデーションにすることが出来ます。
使用例
struct ContentView: View {
var body: some View {
VStack {
Button(action: {}) {
Text("Button")
.foregroundColor(.white)
.padding(20)
}
.background(
LinearGradient(
colors: [.red, .yellow],
startPoint: .leading,
endPoint: .trailing
)
)
}
}
}
コメント