使图像适合屏幕
Fit the image to the screen
我有所有尺寸的相同图像(320x480 640x960 640x1136 750x1334 1242x2208),我将这些图像用于启动屏幕(资产 -> 新 iOS 启动图像)。
我想在应用程序 运行 时间 select 中使用这些图像(在 UIImageView 中)使图像适合所用设备的屏幕尺寸。
在 Launch Screen 中是完美的,但是如果我将 LaunchImage 用于 UIImageView,则视图中的图像会有所不同。
在这个link里面有我的测试代码(Launch.zip)https://github.com/Volpesio/Launch.git
此代码 运行 Launch 图像(完美),在显示一个 UIImageView 后,它应该使用与 Launch 相同的图像但不同
如何调整大小或如何select 为所用设备调整正确的图像?
请你帮帮我..
我用这段代码解决了它:
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"正确的图像
我有所有尺寸的相同图像(320x480 640x960 640x1136 750x1334 1242x2208),我将这些图像用于启动屏幕(资产 -> 新 iOS 启动图像)。 我想在应用程序 运行 时间 select 中使用这些图像(在 UIImageView 中)使图像适合所用设备的屏幕尺寸。 在 Launch Screen 中是完美的,但是如果我将 LaunchImage 用于 UIImageView,则视图中的图像会有所不同。
在这个link里面有我的测试代码(Launch.zip)https://github.com/Volpesio/Launch.git 此代码 运行 Launch 图像(完美),在显示一个 UIImageView 后,它应该使用与 Launch 相同的图像但不同
如何调整大小或如何select 为所用设备调整正确的图像? 请你帮帮我..
我用这段代码解决了它:
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"正确的图像