반응형
Hacking with Swift 사이트의 강좌 번역본입니다.
How to use images and other views as a backgrounds
배경 색상을 지정하는 것보다, 동일한 background() modifier을 사용해서 배경 이미지(image)를 지정할 수 있습니다.
예를들어, 텍스트뷰를 큰 폰트로 만들고나서, 그 뒤에 100x100 이미지를 배치합니다:
Text("Hacking with Swift")
.font(.largeTitle)
.background(
Image("example-image")
.resizable()
.frame(width: 100, height: 100))
하지만, SwiftUI는 이미지여야할 필요는 없습니다 - 실제로 배경에 대해서 모든 종류의 뷰를 사용할 수 있습니다. 예를들어, 동일한 텍스트 뷰를 만들고 그 뒤에 200x200 빨간색 원을 배치합니다.
Text("Hacking with Swift")
.font(.largeTitle)
.background(Circle()
.fill(Color.red)
.frame(width: 200, height: 200))
기본적으로 배경 뷰는 자동으로 완전히 보이는데 필요한 만큼 공간을 차지하지만, 원하는 경우에 clipped() modifier을 사용해서 부모 뷰의 크기를 잘라낼 수 있습니다.
Text("Hacking with Swift")
.font(.largeTitle)
.background(Circle()
.fill(Color.red)
.frame(width: 200, height: 200))
.clipped()
명확하게 하기 위해, 배경으로 모든 뷰를 사용할 수 있습니다 - 예를들어, 원하는 경우에 다른 텍스트 뷰를 사용할 수 있습니다.
반응형
'SwiftUI > Text and images' 카테고리의 다른 글
How to display solid shapes (0) | 2019.11.14 |
---|---|
How to render a gradient (0) | 2019.11.14 |
How to tile an image (0) | 2019.11.14 |
How to adjust the way an image is fitted to its space (0) | 2019.11.14 |
How to draw images using Image views (0) | 2019.11.14 |
How to add spacing between letters in text (0) | 2019.11.14 |
How to format text inside text views (0) | 2019.11.14 |
How to style text views with fonts, colors, line spacing, and more (0) | 2019.11.14 |