Language/Swift
SwiftUI를 이용한 Shape 지정하기
IFLA
2022. 12. 9. 10:01
SwiftUI에는 사각형, 원 및 캡슐과 같은 여러 가지 기본 제공 모양이 있으며 필요에 따라 각 모양을 만들고 색상을 지정하고 배치할 수 있다.
기본 코드
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Circle()
.fill(Color.yellow)
.frame(width: 100, height: 100)
Rectangle()
.fill(Color.blue)
.frame(width: 100, height: 100)
RoundedRectangle(cornerRadius: 20)
.fill(Color.green)
.frame(width:200, height: 100)
Capsule()
.fill(Color.black)
.frame(width: 200, height: 100)
}
}
}
실행 화면

개발자 Document
- Circle() : https://developer.apple.com/documentation/swiftui/circle
- Rectangle() : https://developer.apple.com/documentation/swiftui/rectangle
- RoundedRectangle() : https://developer.apple.com/documentation/swiftui/roundedrectangle
- Capsule() : https://developer.apple.com/documentation/swiftui/capsule