I'm building up a set of Complications and have come to the CLKComplicationTemplateUtilitarianLargeFlat which only has one textProvider.
I want to display some text, along with a relative date. So I tried doing this:
let date = CLKRelativeDateTextProvider(date: NSDate(), style: style, units: units)
let template = CLKComplicationTemplateUtilitarianLargeFlat()
template.textProvider = CLKSimpleTextProvider(text: "next: \(date)")
But all I get is:
<CLKRelativeDateTextProvider: 0x79860b80>
Can you extract the raw text from the CLKRelativeDateTextProvider or combine it with a CLKSimpleTextProvider in some way?
Pass in the CLKRelativeDateTextProvider object to the format string, as mentioned in Apple's code:
@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
Here is an example:
id relativeDate = [CLKRelativeDateTextProvider textProviderWithDate:[NSDate dateWithTimeIntervalSinceNow:12 * 60]
style:CLKRelativeDateStyleNatural
units:NSCalendarUnitMinute];
template.textProvider = [CLKTextProvider textProviderWithFormat:@"next: %@", relativeDate];
The time shown in the date provider will still update as time passes without having to refresh anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With