是否可以像这样在Apple Watch应用中添加滚动报价文本视图?
最佳答案
这是不可能的。但有一个解决方案...
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)
}
}