本文介绍了如何在没有 Storyboard 的情况下在 Xcode 中创建一个空应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Xcode6
在创建新项目时删除了 Empty Application
模板.我们如何在 Xcode6
及更高版本中创建一个空的应用程序(没有 Storyboard),就像在早期版本中一样?
Xcode6
has removed the Empty Application
template when creating a new project. How can we create an empty application (without Storyboard) in Xcode6
and above, like in earlier versions?
推荐答案
XCode6
及以上版本没有选项可以像 XCode5
和早些时候.但是我们仍然可以通过以下步骤创建没有 Storyboard
的应用程序:
There is no option in XCode6
and above versions for directly creating an Empty Application as in XCode5
and earlier. But still we can create an application without Storyboard
by following these steps:
- 创建一个
单视图应用
. - 删除
Main.storyboard
和LaunchScreen.xib
(选择它们,右键单击,然后选择从项目中删除它们,或完全删除它们). - 删除主故事板文件基本名称"和启动屏幕界面"文件库名称"
Info.plist
文件中的条目. - 打开 AppDelegate.m,然后编辑 applicationDidFinishLaunchingWithOptions,使其看起来像这样:
- Create a
Single View Application
. - Remove
Main.storyboard
andLaunchScreen.xib
(select them, right-click, and choose to eitherremove them from the project, or delete them completely). - Remove "Main storyboard file base name" and "Launch screen interfacefile base name" entries in
Info.plist
file. - Open AppDelegate.m, and edit applicationDidFinishLaunchingWithOptions so that it looks like this:
Swift 3 及更高版本:
Swift 3 and above:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.backgroundColor = UIColor.white
self.window?.makeKeyAndVisible()
return true
}
Swift 2.x:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.backgroundColor = UIColor.whiteColor()
self.window?.makeKeyAndVisible()
return true
}
目标-C:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.rootViewController = [[ViewController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
这篇关于如何在没有 Storyboard 的情况下在 Xcode 中创建一个空应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!