Backgrounds, Overlays
Backgrounds
Text("Hello, World!")
.background(
Color.red
LinearGradient(
gradient: Gradient(colors: [Color.red, Color.blue]),
startPoint: .leading,
endPoint: .trailing
)
Circle()
)
- 여러개를 복수로 추가할 수 있다.(Overlays도 동일)
Text("Hello, World!")
.background(
Circle()
.fill(
LinearGradient(
gradient: Gradient(colors: [Color.red, Color.blue]),
startPoint: .leading,
endPoint: .trailing
)
)
.frame(width: 100, height: 100, alignment: .center)
)
.background(
Circle()
.fill(
LinearGradient(
gradient: Gradient(colors: [Color.blue, Color.red]),
startPoint: .leading,
endPoint: .trailing
)
)
.frame(width: 120, height: 120, alignment: .center)
)
Overlays
Circle()
.fill(Color.pink)
.frame(width: 100, height: 100)
.overlay(
Text("A")
.font(.largeTitle)
.foregroundColor(.white)
Circle()
)
- Overlay안의 뷰에 Overlay를 추가할 수 있다.(Backgrounds도 동일)
- 뷰를 기준으로 Overlay를 정렬할 수 있다.(Backgrounds도 동일)
Circle()
.frame(width: 100, height: 100)
.foregroundColor(.red)
.overlay(
Circle()
.frame(width: 40, height: 40)
.overlay (
Text("1")
.foregroundColor(.white)
)
, alignment: .bottomTrailing)