微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift – 你能从CLKRelativeDateTextProvider中提取文本吗?

我正在构建一组并发症,并且已经进入CLKComplicationTemplateUtilitarianLargeFlat,它只有一个textProvider.

我想显示一些文本,以及相对日期.所以我尝试这样做:

let date = CLKRelativeDateTextProvider(date: NSDate(),style: style,units: units)  
let template = CLKComplicationTemplateUtilitarianLargeFlat()  
template.textProvider = CLKSimpleTextProvider(text: "next: \(date)")

但我得到的只是:

<CLKRelativeDateTextProvider: 0x79860b80>

你能从CLKRelativeDateTextProvider中提取原始文本还是以某种方式将它与CLKSimpleTextProvider结合起来?

解决方法

将CLKRelativeDateTextProvider对象传递给格式字符串,如Apple的代码中所述:

@interface CLKTextProvider : NSObject <NScopying>

// By passing one or more CLKTextProviders in the format substitutions,you can add text around the output of a text provider.
+ (CLKTextProvider *)textProviderWithFormat:(Nsstring *)format,... NS_FORMAT_FUNCTION(1,2);

@property (nonatomic) UIColor *tintColor;

@end

这是一个例子:

id relativeDate = [CLKRelativeDateTextProvider textProviderWithDate:[NSDate dateWithTimeIntervalSinceNow:12 * 60]
                                                              style:CLKRelativeDateStyleNatural
                                                              units:NSCalendarUnitMinute];

template.textProvider = [CLKTextProvider textProviderWithFormat:@"next: %@",relativeDate];

日期提供程序中显示的时间仍将随着时间的推移而更新,而无需刷新任何内容.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐