Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ch20. 計算器 (Mac 版本).

Similar presentations


Presentation on theme: "Ch20. 計算器 (Mac 版本)."— Presentation transcript:

1 Ch20. 計算器 (Mac 版本)

2 20.1 建立一個計算器的專案 開啟 Xcode,選取Create a new Xcode project,然後選取 macOS -> Application -> Cocoa。

3 專案設定

4 20.2 UI 設計 這裡的介面與製作 iOS App 介面有所不同。
不同於 iOS 初始的單一 View Controller,在 OS X 上多了 Main Menu 以及 Window Controller,不過,目前只要注意 View Controller 就可以。

5 完成之UI設計

6 20.3 UI 與程式碼的結合 要注意的是,在 OS X 中,Label 的連結繼承的是 NSTextField,這 與 iOS 的 UILabel 有所不同,所以在稍後程式碼的部分也略有所差 異。 而 Push Button 的連結,注意要將 Connection 欄位值改為 Action。 並請在Name欄位填入適當的名稱,如number1、number2…等等。

7 20.4 完整程式碼 與 iOS 專案不同之處在於 import Cocoa 以及繼承 NSViewController, 不過在本範例中,程式碼大至相同,只在 Label 字串的程式碼略 有所不同,在 OS X 上使用 resultBar.stringValue,而非 resultBar.text!。 @IBAction func number1(_ sender: AnyObject) { resultBar.stringValue += "1" resultBar.stringValue = checkNumber(labelText: resultBar.stringValue) }


Download ppt "Ch20. 計算器 (Mac 版本)."

Similar presentations


Ads by Google