這本書的筆記
這是本書第一章谊娇,非常簡(jiǎn)單的肺孤。
打開開始項(xiàng)目。run:
創(chuàng)建Watch Kit App:
選擇
運(yùn)行:
看下項(xiàng)目的工程目錄:
1.HelloAppleWatch WatchKit App目錄下有個(gè)Interface.storyboard济欢。它是用來(lái)設(shè)計(jì)我們的app的赠堵。
2.HelloAppleWatch WatchKit App Extension中有個(gè)InterfaceController,它類似于iOS中UIViewController
創(chuàng)建Watch app類似于創(chuàng)建iOS app法褥,在sb中創(chuàng)建好UI茫叭,然后把UI object鏈接到Controller
我們先放個(gè)label上去:
把label的屬性設(shè)置為下圖,watch app的布局方式和iOS不同半等,不能隨便拖動(dòng)label的位置揍愁,通過設(shè)置Alginment設(shè)置它的位置:
label的size根據(jù)它的內(nèi)容變化:
Setting label text in code
把label鏈接到Controller:
用代碼在willActivate設(shè)置label的內(nèi)容:
Apple's color emoji font
接下來(lái)我們用emoji來(lái)把文字替換掉呐萨。
選擇Hello,然后按control + command + 空格莽囤,選擇你想要得表情谬擦,重復(fù)下面操作:
Casting emoji fortunes
Sharing EmojiData.swift between iPhone and Watch apps
把想共用的文件:
Creating a random emoji fortune
1.在InterfaceController中添加:
2.在InterfaceController中willActivate()加入下面的代碼:
run:
Tell me another one...
Replacing the label with a button
打開Interface.storyboard刪除label,改成拖個(gè)button進(jìn)去,把它的Alignment改成下面那樣朽缎,還有button在Height,改成是watch屏幕的高度的0.9
然后添加下面的代碼:
Dressing up your app
接下來(lái)為應(yīng)用添加背景惨远。先添加資源:
Devices那里注意選擇Apple Watch