IOS full-screen background, multiple button location adaptation (swift), iosswift
I 've written a lot of blogs recently. In fact, most of them are just a few essays. I just sorted this section and published it.
In this article, we will talk about how to place multiple buttons in a fixed position in the face of full-screen background images, is a method that saves effort.
The image is like this. Repeat the problem: for example, if I want to place five buttons on the above full screen background m u r p and visit the official website, I need to adapt to various types of mobile phones.
I solve it like this (StoryBoard ):
First, drag four viewcontrollers In the storyBoard and set the screen size to 3.5, 4.0, 4.7, and 5.5 respectively. Set the background image separately and place the fixed button in a fixed place.
Then, you can determine different screen sizes to load different storyboards. The Code is as follows: (swift ).
1 let screenHeight = UIScreen.mainScreen().bounds.size.height 2 var storyBoards:UIStoryboard = UIStoryboard(name: "Main", bundle: nil) as UIStoryboard 3 if (screenHeight <= 480.0) { 4 5 viewCon = storyBoards.instantiateViewControllerWithIdentifier("First3.5") as! FirstViewController 6 }else if (screenHeight <= 568.0) { 7 8 viewCon = storyBoards.instantiateViewControllerWithIdentifier("First4.0") as! FirstViewController 9 }else if (screenHeight <= 667.0) {10 11 viewCon = storyBoards.instantiateViewControllerWithIdentifier("First4.7") as! FirstViewController12 }else if (screenHeight <= 736.0) {13 14 viewCon = storyBoards.instantiateViewControllerWithIdentifier("First5.5") as! FirstViewController15 }16 17 var naviCon:MainNavigationController = MainNavigationController(rootViewController:viewCon)
In this way, you can adapt all of them.
A friend who wants to see the code: --> github: A Demo partner can see it.