我有所有尺寸的相同图像(320x480 640x960 640x1136 750x1334 1242x2208),并且我将这些图像用于启动屏幕(资源 -> 新的 iOS 启动图像)。 我想在应用程序的运行时使用这些图像(在 UIImageView 中),选择适合所使用设备屏幕尺寸的图像。 在启动屏幕中是完美的,但如果我使用 UIImageView 的 LaunchImage, View 中的图像会有所不同。
在此链接中有我的测试代码(Launch.zip) https://github.com/Volpesio/Launch.git 这段代码(完美)运行Launch Image,在显示一个UIImageView后,它应该使用与Launch相同的图像,但有所不同
如何调整大小或如何为所使用的设备选择正确的图像? 请你帮帮我..
最佳答案
我用这段代码解决了这个问题:
extension UIImage {
convenience init?(fullscreenNamed name: String) {
switch UIScreen.mainScreen().bounds.size.height {
case 480: //iPhone 4/4s
self.init(named: "\(name)-700@2x.png")
case 568: //iPhone 5/5s
self.init(named: "\(name)-700-568h@2x.png")
case 667: //iPhone 6/6s
self.init(named: "\(name)-800-667h@2x.png")
case 736: //iPhone 6+/6s+
self.init(named: "\(name)-800-Portrait-736h@3x.png")
default:
self.init(named: name)
}
}
}
我采用“LaunchImage”为正在使用的设备屏幕的正确图像
关于iphone - 使图像适合屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36682614/