ios 目标 c:如何设置 UIImageView 图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23261605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Objective c: How to set the UIImageView image
提问by Rajaram
hai iam new one for objective c
and iOS
development
hai iam new one for objective c
and iOS
development
Set the UIImageview
image. try the following code
设置UIImageview
图像。试试下面的代码
arrowImgVw is UIImageView Class object
arrowImgVw is UIImageView Class object
UIImage *image=[[UIImage alloc]init];
image=[UIImage imageNamed:@"return_journey_denoter.png"];
arrowImgVw.image = image;
回答by morroko
hey you are wrong in some point use this code for adding an image into UIImageView and display it on iPhone devide
嘿,您在某些方面错了,请使用此代码将图像添加到 UIImageView 并在 iPhone 上显示
UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
//Allocating imageView and set its frame.
//分配imageView并设置它的frame。
myImage.image = [UIImage imageNamed:@"return_journey_denoter.png"];
//add image into imageview
//添加图片到imageview
[self.view addSubview:myImage];
// add imageview into your viewcontroller's view
// 将 imageview 添加到您的视图控制器的视图中
回答by Sourabh Kumbhar
To simply set image to imageView just one line of code
只需一行代码即可将图像设置为 imageView
arrowImgVw.image = [UIImage imageNamed:@"return_journey_denoter.png"];
回答by Suhit Patil
The code you have written
is ok for setting image
, just check the name
for the given image or you can try following code...
你的代码written
是确定的setting image
,只是检查name
对于给定的图像或者你可以尝试下面的代码...
UIIImageView *arrowImgVw = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,200,200)]; //just example change the frame as per your need
arrowImgVw.image = [UIImage imageNamed:@"return_journey_denoter"];
回答by Brahmaiah Thota
In Swift3.0
在Swift3.0 中
To set image to your imageView use belwo code.
要将图像设置为您的 imageView,请使用 belwo 代码。
arrowImgVw.image = UIImage(named: "return_journey_denoter.png")
回答by Sateesh Pasala
If you are trying to access the image from the assets . Use the below code
如果您尝试从资产访问图像。使用下面的代码
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
UIImage *image = [UIImage imageNamed:@"image" inBundle:bundle compatibleWithTraitCollection:nil];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
image should be inside your assets folder .
图像应该在您的资产文件夹内。