iOS全屏的背景,多個按鈕位置適配(swift),iosswift

來源:互聯網
上載者:User

iOS全屏的背景,多個按鈕位置適配(swift),iosswift

最近寫部落格比較多,其實大多是之前的隨筆,這一段整理一下,發布出來。

今天這篇文章,說一下,面對全屏的背景圖片,要在固定的位置放置多個按鈕的問題我的解決辦法,其實很土,談不上是技術,就是一種方法,很省力。

圖片就是這樣的。再重複一下問題:例如我要在上述全屏的背景上的 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的小夥伴看過來

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.