Iwatch: Wkinterfacelabel How to Stop Text from Being Cut Off with "..." at The End of a Label

How does WKInterfaceLabel Min Scale work? It gets ignored once set values

Ok, I've received a followup on my bug report, apparently the Min Scale flag only applies for labels that are precisely of one line.

Hi Marco,

This is a follow-up regarding Bug ID# 22774281.

Please update your report directly at http://bugreport.apple.com for
the fastest response. Please do not email your updates.

Engineering has determined that this issue behaves as intended based
on the following information:

This is a known behavior of UILabel. If you request multiple lines,
you will truncate. We don’t scale to just fit multiple lines, only
one.

Watch App - Replace ... when text is too long

Sadly, this is not possible. Apple doesn't provide any sort of way on managing that.

A possible, but rather complicated solution would be making a costume picker with labels with multiple lines and using the newly implemented WKCrownSequencer as well as the WKCrownDelegate in watchOS 3 to detect the state of the digital crown. The default picker animations might be impossible or very difficult to reproduce, but it might fix your problem.

Compare WKInterfaceLabel Text to Another NSString

There's no supported way to get the text, just as you said, however you may want to use the accessibility elements as "option".

Here's the idea:

When self.label text is set (either in code or storyboard) also set the corresponding accessibility label/value. When you need to read/update the label text, just make sure you use the accessibility values instead.

self.label.text = @"foo";
self.label.accessibilityValue = @"foo";

if ([self.label.accessibilityValue isEqualToString:someString]) {
self.label.text = @"bar";
self.label.accessibilityValue = @"bar";
...
}

Plus it's how you would use accessibility anyway so it's legal. There may be other ways to accomplish, but this seems to be the quickest and safest way to do what you want.

Scroll long text inside WKInterfaceLabel?

You can definitely do this. All you need to do is set the following properties on the WKInterfaceLabel in the Storyboard.

  • Label => Lines = 0 (WatchKit will set the right number)
  • Size => Width = "Relative to Container"
  • Size => Height = "Size to Fit Content"

This will let you scroll to your heart's content. I just mocked it up in a sample app and it works exactly as you would expect.

Hope that helps!

WatchOS2 - Is there any way to scroll a label horizontally?

No that is not possible. When the label is wider than the screen it just gets truncated. Putting it in a horizontal WKInterfaceGroup does not help either.

The only thing on an Apple Watch to remotely represent horizontal scrolling is having a Page-Based Interface. There you can swipe horizontally between different WKInterfaceControllers.

If a text is too long for your WKInterfaceLabel and you do not want to have multiple lines you could autoscroll the text:

class InterfaceController: WKInterfaceController {

@IBOutlet var label: WKInterfaceLabel!

let fullText = "This is a long text that should scroll."
var scrolledText: String?
var timer: NSTimer?

override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)

scrolledText = fullText
timer = NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: Selector("timerDidFire:"), userInfo: nil, repeats: true)
label.setText(scrolledText)
}

override func didDeactivate() {
timer?.invalidate()
}

func timerDidFire(timer: NSTimer) {
if scrolledText!.characters.count > 1 {
scrolledText!.removeAtIndex(scrolledText!.startIndex)
} else {
scrolledText = fullText
}
label.setText(scrolledText)

}
}

Although this feels a bit too much like the 90ies for me ;-)

WatchKit adding margin to Label

You should create a WKInterfaceGroup and add the WKInterfaceLabel inside the group. You can manage the margin/padding using that group.

Sample Image



Related Topics



Leave a reply



Submit