iOS/SwiftUI
[SwiftUI] Image
HarryJeonn
2022. 4. 24. 15:45
Image를 어떻게 사용하는지 알아보자
import SwiftUI
struct CircleImageView: View {
var body: some View {
Image("profile")
// 사이즈 조절
.resizable()
// 비율 조절
.scaledToFit()
// .aspectRatio(contentMode: .fill)
// 크기 조절
.frame(width: 300, height: 300)
// 이미지 자르기
// .clipped()
.clipShape(Circle())
// 그림자
.shadow(color: .gray, radius: 2, x: 5, y: 10)
// Overlay
.overlay(Circle().stroke(Color.red, lineWidth: 4)) // 라운드
.overlay(Circle().foregroundColor(.black.opacity(0.3))) // 반투명
.overlay( // 글자
Text("Harry")
.foregroundColor(.white)
.font(.system(size: 30))
.fontWeight(.bold)
)
}
}
🤔
Text에 대해 알아볼 때도 느꼈지만 코드 한줄로 손쉽게 UI를 구성할 수 있는 것은 확실히 편한 것 같다.