Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ClockKit
- class ComplicationController: NSObject, CLKComplicationDataSource {
- // MARK: - Timeline Configuration
- func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
- handler(CLKComplicationTimeTravelDirections())
- }
- func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
- if complication.family == .circularSmall {
- let template = CLKComplicationTemplateCircularSmallRingImage()
- template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Circular")!)
- let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
- handler(timelineEntry)
- } else if complication.family == .utilitarianSmall {
- let template = CLKComplicationTemplateUtilitarianSmallRingImage()
- template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Utilitarian")!)
- let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
- handler(timelineEntry)
- } else if complication.family == .modularSmall {
- let template = CLKComplicationTemplateModularSmallRingImage()
- template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Modular")!)
- let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
- handler(timelineEntry)
- } else {
- handler(nil)
- }
- }
- func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
- switch complication.family {
- case .circularSmall:
- let image = UIImage(named: "Circular")
- let template = CLKComplicationTemplateCircularSmallSimpleImage()
- template.imageProvider = CLKImageProvider(onePieceImage: image!)
- handler(template)
- case .utilitarianSmall:
- let image = UIImage(named: "Utilitarian")
- let template = CLKComplicationTemplateUtilitarianSmallSquare()
- template.imageProvider = CLKImageProvider(onePieceImage: image!)
- handler(template)
- case .modularSmall:
- let image = UIImage(named: "Modular")
- let template = CLKComplicationTemplateModularSmallSimpleImage()
- template.imageProvider = CLKImageProvider(onePieceImage: image!)
- handler(template)
- default:
- handler(nil)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement