如果專案一開始沒有使用 Storyboard,也不必急著重建。可以先新增一個 Storyboard 檔案,選擇適合的裝置類型,並為它命名。接著在 Info.plist 中加入 UIMainStoryboardFile,讓 App 啟動時知道要載入哪個 Storyboard。
在 Storyboard 中新增 View,並將它的 Class 指定為專案裡既有的 ViewController。這樣就能沿用原本的控制邏輯,而不必重新建立類別。以下範例會在 viewDidLoad 中建立一個 UILabel,設定文字、字體與置中位置。
self.myLabel = [[UILabel alloc] initWithFrame:labelFrame];
self.myLabel.text = @"Archy is Studying IOS 5 Programming";
[self.view addSubview:self.myLabel];
若原本已有 xib 或純程式碼畫面,加入 Storyboard 後要確認啟動入口是否正確,避免出現兩個起始畫面。完成設定後,就能逐步把既有流程遷移到 Storyboard 中。