SwiftUI中的元件要呈現圓角很容易,使用cornerRadius 修飾器即可,順便透過LinearGradient填入一個漸層色背景。
ZStack {
LinearGradient(
colors: [.white, .indigo.opacity(0.4)],
startPoint: .top,
endPoint: .bottom
)
Text("Hello, World!")
}
.frame(width: 200, height: 100)
.cornerRadius(10)
圓角邊框需要在圖形上使用overlay修飾器疊上一個圓角矩形才能正確出現圓角邊框。
ZStack {
LinearGradient(
colors: [.white, .indigo.opacity(0.4)],
startPoint: .top,
endPoint: .bottom
)
Text("Hello, World!")
}
.frame(width: 200, height: 100)
.cornerRadius(10)
.overlay {
RoundedRectangle(cornerRadius: 10)
.stroke(.indigo, lineWidth: 2)
}