gpt4 book ai didi

swift - 如何在 CLKComplicationDataSource 中为两个并发症定义数据

转载 作者:搜寻专家 更新时间:2023-11-01 06:43:17 24 4
gpt4 key购买 nike

所以,我对 ClockKit Complications 有点陌生,我想知道如何为两个 Complications 制作占位符模板。

到目前为止我的代码:

func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached

let template = CLKComplicationTemplateModularLargeStandardBody()
template.headerTextProvider = CLKTimeIntervalTextProvider(startDate: NSDate(), endDate: NSDate())
template.body1TextProvider = CLKSimpleTextProvider(text: "Label 1", shortText: "1")
template.body2TextProvider = CLKSimpleTextProvider(text: "Label 2", shortText: 2)

handler(template)

}

有人能帮忙吗?

最佳答案

根据complication.family添加一个switch语句来返回特定的并发症:

func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached
var template: CLKComplicationTemplate? = nil
switch complication.family {
case .ModularSmall:
template = nil
case .ModularLarge:
let modularLargeTemplate = CLKComplicationTemplateModularLargeStandardBody()
modularLargeTemplate.headerTextProvider = CLKTimeIntervalTextProvider(startDate: NSDate(), endDate: NSDate())
modularLargeTemplate.body1TextProvider = CLKSimpleTextProvider(text: "Label 1", shortText: "1")
modularLargeTemplate.body2TextProvider = CLKSimpleTextProvider(text: "Label 2", shortText: "2")
template = modularLargeTemplate
case .UtilitarianSmall:
template = nil
case .UtilitarianLarge:
let utilitarianLargeTemplate = CLKComplicationTemplateUtilitarianLargeFlat()
utilitarianLargeTemplate.textProvider = CLKSimpleTextProvider(text: "Label 1")
template = utilitarianLargeTemplate
case .CircularSmall:
let circularSmallTemplate = CLKComplicationTemplateCircularSmallRingText()
circularSmallTemplate.textProvider = CLKSimpleTextProvider(text: "1")
circularSmallTemplate.fillFraction = 0.5
circularSmallTemplate.ringStyle = CLKComplicationRingStyle.Closed
template = circularSmallTemplate
}
handler(template)
}

关于swift - 如何在 CLKComplicationDataSource 中为两个并发症定义数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33441489/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com