- Total
꿈꾸는리버리
SwiftUI Widget 딱대(짐).. : Lock Screen Widget 본문
☁️ Widget 시리즈
기본 시리즈
SwiftUI Widget 딱대.. (1/3) 위젯 기본 개념 + 구현
SwiftUI Widget 딱대.. (2/3) : 앱 내의 데이터를 widget에 띄우기
SwiftUI Widget 딱대.. (3/3) : 위젯을 눌렀을 때 다른 화면으로 뜨게 하기
SwiftUI Widget 딱대.. ( Lock Screen Widget )
에러 시리즈
SwiftUI Widget 딱대(짐).. : 위젯 memory 제한
SwiftUI Widget 딱대(짐).. : localization 적용
SwiftUI Widget 딱대(짐).. : 위젯에 폰트가 안 먹혀요...
SwiftUI Widget 딱대(짐).. : 딥링크가 안되는 뎁숑 ?
SwiftUI Widget 딱대(짐).. : Xcode Widget error Failed to show Widget 고치기
SwiftUI Widget 딱대(짐).. : Widget에 보여지는 순서 수정하기
SwiftUI Widget 딱대(짐).. : iOS 18 이후 Tint Widget 흰 화면 에러 해결SwiftUI Widget 딱대(짐).. : 딥링크가 안되는 뎁숑 ?
✈️ Lock Screen Widget
- 이렇게 락스크린 위젯은 3가지 종류이다. 그리고 Widget을 개발했다면 코드 몇 줄만 추가하면 바로 넣을 수 있다니.. 넘 좋잖아???
- 참고로 잠금 화면 위젯은 16.0+부터 이용 가능하다.

✈️ 구현 방법
1. StaticConfiguration으로 생성하기
( Widget을 처음 만들어본다면 이 포스팅을 우선 참고해주세요 ! )
- 만약 위젯을 처음 만든다면, 위젯 생성할 때 include Configuration App Intent를 빼기.


- 이미 위젯을 작성했다면, StaticConfiguration으로 변경해야 한다.
( AppIntentConfiguration의 경우에는 지원을 안하는 것 같은데, 안해봐서 확실치는 않음 ... )
Creating accessory widgets and watch complications | Apple Developer Documentation
Support accessory widgets that appear on the Lock Screen and as complications on Apple Watch.
developer.apple.com

2. WidgetFamily 추가
지원하는 WidgetFamily에 .accessoryCircular, .accessoryInline, .accessoryRectangular를 추가한다.
StaticConfiguration(kind: kind, provider: DDayTimelineProvider()) { entry in
// 내용
}
// supportedFamilies에 추가 ( 기존 위젯들도 지원하면 같이 입력 )
.supportedFamilies([.accessoryCircular, .accessoryInline, .accessoryRectangular])
3. View 그리기
struct OurDdayDefaultWidgetEntryView : View {
@Environment(\.widgetFamily) private var widgetFamily
var entry: DDayTimelineProvider.Entry
var body: some View {
switch widgetFamily {
case .accessoryCircular:
// View 추가
case .accessoryInline:
// View 추가
case .accessoryRectangular:
// View 추가
}
}
}
+ 약간의 꿀팁
1) ViewThatFits : iOS 16.0 부터 지원
화면이 짤리면 ( 텍스트가 길어서 뒷 내용이 ...으로 된다면 ) 이런식으로 해서 Font 크기를 조절할 수 있다.
ViewThatFits {
VStack {
Text(icon)
Text(DdayString)
}
.font(.lee_18)
VStack {
Text(icon)
Text(DdayString)
}
.font(.lee_15)
}
2) 프리뷰
struct MyLockScreenWidget_Previews: PreviewProvider {
static var previews: some View {
Group {
InlineViewForWidget(Dday: ddayCount)
.previewContext(WidgetPreviewContext(family: .accessoryInline))
CircularViewForWidget(Dday: ddayCount)
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
.containerBackground(for: .widget) {
Color.white
}
RectangularViewForWidget(Dday: ddayCount, title: title, meetingDateModel: meetingDateModel)
.previewContext(WidgetPreviewContext(family: .accessoryRectangular))
.containerBackground(for: .widget) {
Color.white
}
}
}
}
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
How to add and edit widgets on your iPhone - Apple Support
With widgets, you get timely information from your favorite apps at a glance on your Home Screen, Lock Screen, or Today View.
support.apple.com