Xcode 5 & Asset Catalog: How to reference the LaunchImage?

前端 未结 14 1562
萌比男神i
萌比男神i 2020-11-28 18:17

I am using Xcode 5\'s Asset Catalog, and I would like to use my LaunchImage as the background image of my home view (a pretty common practice to make the transi

14条回答
  •  甜味超标
    2020-11-28 18:41

    Swift version of Cherpak Evgeny's answer:

        func splashImageForOrientation(orientation: UIInterfaceOrientation) -> String {
            var viewSize = self.view.bounds.size
            var viewOrientation = "Portrait"
            if UIInterfaceOrientationIsLandscape(orientation) {
               viewSize = CGSizeMake(viewSize.height, viewSize.width)
               viewOrientation = "Landscape"
            }
            let imagesDict = NSBundle.mainBundle().infoDictionary as Dictionary!
            let imagesArray = imagesDict["UILaunchImages"] as NSArray
            for dict in imagesArray {
                let dictNSDict = dict as NSDictionary
                let imageSize = CGSizeFromString(dictNSDict["UILaunchImageSize"] as String)
                if CGSizeEqualToSize(imageSize, viewSize) && viewOrientation == (dictNSDict["UILaunchImageOrientation"] as String) {
                    return dictNSDict["UILaunchImageName"] as String
                }
            }
            return ""
        }
    

提交回复
热议问题