1.運行xcode甘改,F(xiàn)ile 新建 project 選擇 IOS Application 創(chuàng)建 single view Application.
2.創(chuàng)建好后征字,把工程目錄下的Main.storyboard和LaunchScreen.xib刪除晨川。
3.打開Info.plist,把Launch screen interface file base name,以及Main storyboard file base name兩項,刪除(點擊旁邊的減號即可)瞄沙。
4.打開工程項目屬性文件,點擊Target下面的第一項慌核,再選擇General選項卡距境,向下找到Use Asset Catalog按鈕。點擊它垮卓。彈出對話框垫桂,點擊Migrate即可。這樣扒接,應(yīng)用尺寸就能根據(jù)屏幕大小進行調(diào)整了伪货。
5.最后,在AppDelegate的第一個方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
)里面钾怔,“return”語句之前碱呼,添加必要代碼。
代碼只有3句宗侦,相當于分3步走愚臀。1.創(chuàng)建window;2.設(shè)置window背景矾利;3.使window可見姑裂。
OC和Swift的語法略有不同,但代碼內(nèi)容基本一致男旗。
//OC需要添加的代碼
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//Swift需要添加的代碼
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.backgroundColor = UIColor.whiteColor()
self.window?.makeKeyAndVisible()