Skip to content

SwiftUI Color를 gradient으로 변경하기

1 min read

iOS 16.0 이상부터 사용할 수 있다.

SwiftUI에서 색상에 gradient를 쉽게 입힐 수 있다. iOS 16부터 SwiftUI Color.gradient 프로퍼티를 호출하기만 하면 해당 색상이 자동으로 멋진 그라데이션으로 바뀐다:

VStack {
    Rectangle()
        .fill(.blue)     // 일반 색상
    
    Rectangle()
        .fill(.blue.gradient)    // 일반 색상에 gradient 추가
}
.padding()

파란색 사각형과 그라데이션이 적용된 사각형

참고

gradient | Apple Developer Documentation


Share this post on:

Previous Post
SwiftUI에서 PreferenceKey 활용하기
Next Post
iOS 15에서 Date.FormatStyle을 사용하여 Swift에서 날짜 서식 지정하기