如何为4英寸iOS设备指定图像
如何为如何为4英寸iOS设备指定图像,ios,Ios,如何为4英寸iOS设备全屏指定图像。568@2x仅适用于默认图像任何方法都将被完全使用。请分享一些代码片段。在这种情况下,您需要为UIImage编写一个分类方法,并在所有需要全屏图像的地方使用它 还有一个 我的命名惯例: 正常图像:img.png 视网膜图像:img@2x.png 4英寸屏幕:img-4@2x.png 高度是屏幕高度 代码: 类别实施: +(UIImage *) imageNamed5:(NSString *) imgName { NSArray *paths =
4英寸iOS设备全屏指定图像
。568@2x
仅适用于默认图像
任何方法都将被完全使用。请分享一些代码片段。在这种情况下,您需要为UIImage编写一个分类方法,并在所有需要全屏图像的地方使用它
还有一个
我的命名惯例:
- 正常图像:img.png
- 视网膜图像:img@2x.png
- 4英寸屏幕:img-4@2x.png
- 高度是屏幕高度
代码:
类别实施:
+(UIImage *) imageNamed5:(NSString *) imgName
{
NSArray *paths =[imgName componentsSeparatedByString:@"."];
UIImage *img =nil;
if(paths.count == 2){
NSString *imgNme =[paths objectAtIndex:0];
NSString *ext = [paths objectAtIndex:1];
NSString *imgPath;
if(HEIGHT == 568)
{
imgPath = [NSString stringWithFormat:@"%@%@%@",imgNme,@"-4@2x.",ext];
}
else
{
imgPath = imgName;
}
img = [UIImage imageNamed:imgPath];
}
if(img == nil){
img = [UIImage imageNamed:imgName];
}
return img;
}
我用这种方式
Appdelegate *delegate = [[UIApplication sharedApplication]delegate];
//check the height of window
if (delegate.window.frame.size.height == 568)
{
//use image_568@2x
}else{
//use normal image
}
正常图像,如您在iphone4s应用程序中使用的图像。它与iphone4s应用程序兼容。
Appdelegate *delegate = [[UIApplication sharedApplication]delegate];
//check the height of window
if (delegate.window.frame.size.height == 568)
{
//use image_568@2x
}else{
//use normal image
}