Posted at

Apple Watchでカウントアプリ

More than 1 year has passed since last update.


InterfaceController.swift

import WatchKit

import Foundation

class InterfaceController: WKInterfaceController {

@IBOutlet var label: WKInterfaceLabel!
var count:Int = 0
override func awake(withContext context: Any?) {
super.awake(withContext: context)

}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
let fontSize = UIFont.systemFont(ofSize: 90)
let text = String(count)
let attrStr = NSAttributedString(string: text, attributes:[NSFontAttributeName:fontSize])
label.setAttributedText(attrStr)

}

override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
@IBAction func push() {
count += 1
let fontSize = UIFont.systemFont(ofSize: 90)
let text = String(count)
let attrStr = NSAttributedString(string: text, attributes:[NSFontAttributeName:fontSize])
label.setAttributedText(attrStr)
}

}