-
[WidgetKit] WidgetKit 간단하게 알아보기/Widget 2025. 5. 21. 15:05반응형
안녕하세요 아렉스입니다 :> 오늘은 WidgetKit 에 대해 얘기해 보겠습니다.
iOS 개발에서 WidgetKit은 사용자가 iOS 홈 화면, 잠금 화면, 또는 StandBy 모드에서 앱의 중요한 정보를 빠르고 간편하게 확인할 수 있게 해주는 위젯을 만들 때 사용하는 프레임워크
WidgetKit이란?
- Apple의 위젯 개발 프레임워크
- iOS 14 이상부터 도입
- SwiftUI 기반으로 작동
- 앱의 정보를 홈 화면, 잠금 화면, StandBy 등 다양한 위치에 작고 가볍게 시각적으로 표시
WidgetKit으로 무엇을 할 수 있는가 ?
- 위젯
- 스마트 스택 지원
- 워치 컴플리케이션
- 라이브 액티비티
- 컨트롤 위젯
위젯은 크게 configurable, nonconfigurable 두개의 타입으로 볼 수 있습니다.
@main(시작점)부터 구조 살펴보기
WidgetBundle -> Widget -> WidgetConfiguration 으로 구성되어있습니다.
import WidgetKit import SwiftUI @main struct ExWidgetBundle: WidgetBundle { var body: some Widget { ✅ 기본 Widget, Live Activity, Control Widget 등 번들로 묶을 수 있음 ExWidget() ExActivity() } } struct ExWidget: Widget { ✅ widget의 id 역할 let kind: String = "ExWidget" var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: Provider()) { entry in if #available(iOS 17.0, *) { SampleView(entry: entry) .containerBackground(.fill.tertiary, for: .widget) } else { SampleView(entry: entry) .padding() .background() } } .configurationDisplayName("Example Widget") // ✅ 위젯 추가시 표시 될 제목 .description("이건 위젯에 대한 설명") .supportedFamilies([.systemSmall]) // ✅ 지원할 위젯 크기 지정 } }
WidgetConfiguration
위젯의 콘텐츠를 설명하는 유형.
용도에 맞게 사용하면 됩니다.
StaticConfiguration 을 간단하게 살펴보면 TimeProvider 를 인수로 받고 Entry를 통해 View를 그려줍니다.
struct StaticConfiguration<Content> : WidgetConfiguration where Content : View { public var body: some WidgetConfiguration { get } public typealias Body = some WidgetConfiguration init<Provider>( kind: String, provider: Provider, @ViewBuilder content: @escaping (Provider.Entry) -> Content ) where Provider : TimelineProvider }
종류 용도 버전 StaticConfiguration 기본 iOS 14.0 이후 IntentConfiguration configuable widget (동적) iOS 14.0 이후 AppIntentConfiguration configuable widget (동적) iOS 17.0 이후 ActivityConfiguration 라이브 액티비티 iOS 16.1 이후 WidgetKit 매커니즘
2025.05.21 - [분류 전체보기] - [WidgetKit] WidgetKit 매커니즘
지원하는 위젯 종류
HIG 에서 간단하게 확인해볼 수 있습니다.
종류 설명 .systemSmall 작은 정사각형 .systemMedium 가로형 직사각형 .systemLarge 큰 정사각형 .accessoryCircular 잠금화면/StandBy 원형 .accessoryRectangular 잠금화면/StandBy 직사각형 .accessoryInline 텍스트 중심의 최소 위젯 잘못된 내용 혹은 이해가 어려운 내용들은 언제든 댓글에서 의견 교환하고 싶습니다!
공감과 구독은 더 나은 글을 작성되는데 큰 도움이 됩니다.읽어주셔서 감사합니다.
https://developer.apple.com/documentation/widgetkit
WidgetKit | Apple Developer Documentation
Extend the reach of your app by creating widgets, watch complications, Live Activities, and controls.
developer.apple.com
https://developer.apple.com/design/human-interface-guidelines/widgets
Widgets | Apple Developer Documentation
A widget elevates and displays a small amount of timely, relevant information from your app or game so people can see it at a glance in additional contexts.
developer.apple.com
' > Widget' 카테고리의 다른 글
[WidgetKit] WidgetKit 정책과 타임라인(Timeline) 매커니즘 (1) 2025.05.21