3

I am wondering (hoping) that there is a way to scroll a WKInterfaceLabel horizontally?

ICL1901
  • 7,632
  • 14
  • 90
  • 138

1 Answers1

6

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 ;-)

joern
  • 27,354
  • 7
  • 90
  • 105