LoginSignup
6
7

More than 5 years have passed since last update.

初めてのApple Watchアプリ 〜カウントアプリ〜

Last updated at Posted at 2016-11-05

Apple Watchを手に入れたので簡単なCountアプリをswiftで作ってみました。

実際に作ってみる

今回作ったアプリはカウントアプリです。

コードはこんな感じです!

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

}

 ストーリーボード

スクリーンショット 2016-11-05 20.01.54.png

 スクリーンショット

IMG_5591.PNG

最後に

思った以上に簡単に開発できました。Apple Watchをこれからも引き続き開発していきます

参考

6
7
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
6
7