2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Apple Watchでカウントアプリ

Posted at
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)
    }

}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?