2016-10-05 56 views
0

我有imageview n视图控制器,其大小根据iPhone的大小而有所不同。我想设置高度恒定和宽度将会有所不同(framewidth)。我们可以在objectiveview中使用Xcasset在imageview上设置图像吗?

So I decided to keep differnt image in Xcassets of size 
a) (320, 110) i.e framewidth of Iphone 4s , 5s or 5c 
b) (375, 110) i.e framewidth of Iphone 6 or 7 
c) (414, 110) i.e framewidth of Iphone 6s or 7s 

So, my question is, How to set image using XCAssets in objective c? 

回答

2

在你的Images.xcassets你可以添加相同的图像与所有3个图像的大小,而不仅仅是使用它。

要导出图像,并保留所有组织,出口所有的人都用这个名字:

- [email protected] 
- [email protected] 
- [email protected] 

可以为更多信息,请查看本linkUIImageAsset

现在,使用这些图像,您不需要关心尺寸,它会根据手机尺寸选择,只需使用以下命令:

// @ your @interface 
@property (weak, nonatomic) IBOutlet UIImageView *imageView; 

// @ your @implementation 
[self.imageView setImage:[UIImage imageNamed:@"image-name"]]; 
+1

yaa。这是我正在寻找的。非常感谢。 – Sommm

1

如果大小5S,4S,5C,6S等XCAssets你已经设置的图像..所以现在你想只是在你的ImageView您的视图控制器设置为仅映像名称或要设置图像与XCAssets图像名称相同。

相关问题