我一直在XCode這種方式建設一段時間了,我沒有在我的開發中使用任何Xib文件。
它是非常簡單的上手只需按以下步驟操作:
- 創建一個新的單一視圖應用
- 在導航器,刪除這兩個「.storyboard」文件。
- 在「的.plist」文件下支持文件,刪除有關的兩個字符串‘主要故事板文件基本名稱......’
- 在你的‘AppDelegate.m’,包括自定義的UIViewController在頂部,然後
更新「didFinishLaunchingWithOptions」的方法看起來像:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController = [[MyViewController alloc] init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.window makeKeyAndVisible];
return YES;
}
運行應用程序應該表現出你的新屏幕(MyViewController),它在默認情況下黑色的背景。
在你的UIViewController中,你現在可以開始腳本編寫你需要的元素,比如'viewDidLoad'方法。下面的幾個例子:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
myView.backgroundColor = [UIColor greenColor];
[self.view addSubview:myView];
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 180, 50)];
myLabel.font = [UIFont systemFontOfSize:20];
myLabel.text = @"Example";
myLabel.textColor = [UIColor darkGrayColor];
[myView addSubview:myLabel];
}
網上有很多編碼的例子。乾杯。
答案不回答問題(而是鼓勵使用故事板)是不合適的。 – titaniumdecoy
你需要把這個問題縮小到特定的範圍。它目前的狀態太廣泛了。代碼中沒有什麼特別的。去做就對了。我從未在5年多的iOS開發中使用過IB。 – rmaddy
@titaniumdecoy:問題本身不能根據計算器的規則進行回答。 – vikingosegundo