ios - Apple Watch 滚动代码标签

标签 ios user-interface apple-watch

是否可以像这样将滚动代码 TextView 添加到 Apple Watch 应用程序中? Ticker text

最佳答案

这是不可能的。但是有一个变通方法...

class InterfaceController: WKInterfaceController {

@IBOutlet var label: WKInterfaceLabel!

let fullText = "i am  a long text and i am scrollable horizontally lol."
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)

    }

}

关于ios - Apple Watch 滚动代码标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31146171/

相关文章:

ios - 来自字符串时区的日期不符合使用 DateFormatter

ios - 如何在 SKView 之上添加 SCNView

python - 是否有 wxPython( Phoenix ) 的 wx.EVT_CHAR 或 event.GetKeyCode() 等价物?

C# 同时更新两个文本框?

ios - 在真正的 Apple Watch 上调试

ios - Apple WatchOS2 - 我可以一直运行一个应用程序,直到设备没电为止吗?

ios - 设置 HTTP 方法 : @"POST" not working

ios - 在设备之间共享数据(Swift)

javascript - 使用 Bootstrap Dropdown 和 Jquery 更改 Bootstrap 表单

ios - WatchKit 应用程序的部署目标必须等于 iOS 8.2(是 8.3)吗?