最近寫博客比較多,其實大多是之前的隨筆,這一段整理一下,發布出來。
今天這篇文章,說一下,面對全屏的背景圖片,要在固定的位置放置多個按鈕的問題我的解決辦法,其實很土,談不上是技術,就是一種方法,很省力。
圖片就是這樣的。再重復一下問題:例如我要在上述全屏的背景上的 M U R P 和 訪問官方網站五個地方放置五個按鈕,要求適配各種型號手機。
我是這樣解決的(StoryBoard):
首先:在storyBoard里面拖4個ViewController,分別設置screen size 為3.5、 4.0、 4.7、 5.5的尺寸。然后把背景圖片分別設置上去,在固定的地方放置固定的按鈕。
然后在使用的時候通過判斷不同的屏幕尺寸,來加載不同的storyBoard,代碼如下:(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)
這樣一來,就可以全部適配了。
想看代碼的小伙伴:--> github:要Demo的小伙伴看過來
新聞熱點
疑難解答