LoginSignup
6
6

More than 5 years have passed since last update.

WatchKitミニマムサンプル

Last updated at Posted at 2014-12-15

Watch画面にボタンを押すとボタンのタイトルと色が変わるだけのミニマムサンプル

準備

  • Xcode6.2以上でiOSアプリのプロジェクトを作成
  • File / New / Target / Apple Watch / WatchKit Appを選択してターゲット作成

Controllerの編集

  • WatchKit Extension / InterfaceController.m(WKInterfaceControllerの派生クラス)を開く
  • 内容を以下のように書き換える
@interface InterfaceController()
@property(nonatomic, weak) IBOutlet WKInterfaceButton *okButton;
@end

@implementation InterfaceController

- (IBAction) onOk {
    self.okButton.title = @"Changed!";
    self.okButton.color = [UIColor blueColor];
}

@end

Storyboardの編集

  • WatchKit App / Interface.storyboardを開く
  • Interface Controller Scene 上にButtonをD&Dで配置する
  • ボタンを右クリックしてSent Action / Selectorを引っ張ってInterface ControllerのonOKに紐付ける
  • ボタンを右クリックしてReferencing Outlets / New Referencing Outletを引っ張ってInterface ControllerのokButtonに紐付ける

起動

  • シミュレータで実行
  • ボタンを押して変わることを確認!

iOS Simulator Screen Shot - Apple Watch 2014.12.16 0.00.38.png

iOS Simulator Screen Shot - Apple Watch 2014.12.16 0.00.44.png

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