0

I have one phrase that will be the entirety of the complication. Sometimes it is short enough to occupy the header alone. However, sometimes it is too long and I need it to wrap onto the body lines. I can't for the life of me figure out how to get this behavior. For example:

let phrase1 = "Short phrase"

phrase1 is short enough to fit on the header line.

let phrase2 = "Very very very very very very long phrase"

For phrase2, only "Very very ve..." displays on the header line. I need the rest to be shown on the body lines.

Here is the code:

let headerTextProvider = CLKSimpleTextProvider(text: string) //string  is either phrase1 or phrase2
let template = CLKComplicationTemplateModularLargeStandardBody()
template.headerTextProvider = headerTextProvider
let timelineEntry = CLKComplicationTimelineEntry(date: NSDate(), complicationTemplate: template)
handler(timelineEntry)
swiftyboi
  • 2,965
  • 4
  • 25
  • 52

2 Answers2

1

To do this you would need to split the string into two variables, one with "Very very" and one with "very very very very long phrase" and assign them to the headerTextProvider and body1TextProvider value. But since the body1TextProvider will already wrap, have you tried just assigning text just to the body1TextProvider value (assign nothing to the headerTextProvider)?

lehn0058
  • 19,977
  • 15
  • 69
  • 109
  • While `body2TextProvider` is optional, `body1TextProvider` and `headerTextProvider` aren't marked as optional. Perhaps Apple intended the [ModularLargeStandardBody complication](https://developer.apple.com/library/watchos/documentation/ClockKit/Reference/CLKComplicationTemplateModularLargeStandardBody_class/index.html#//apple_ref/occ/instp/CLKComplicationTemplateModularLargeStandardBody/headerTextProvider) have both a header line and body text? –  Dec 31 '15 at 17:46
0

While body1TextProvider will wrap to the second line, if body2TextProvider is nil, headerTextProvider will never wrap to body1TextProvider.

The header and body are formatted differently (i.e. font size and text color), and it would likely be odd to see part of your phrase formatted differently from the remainder.

You could provide a shortText phrase to handle cases where a longer text phrase would not fit.

let headerTextProvider = CLKSimpleTextProvider(text: phrase2, shortText: phrase1)