如何在ImageView中显示图像?

发布于 2024-11-16 06:25:57 字数 51 浏览 3 评论 0原文

我是编程和开发我的第一个应用程序的新手,但我想知道如何将图像显示到 imageView。

I am new to programming and developing my first application, but I want to know that how can I display image to imageView.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

这个俗人 2024-11-23 06:25:57

以编程方式:

来自http://www.iphoneexamples.com/

CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect]; 
[myImage setImage:[UIImage imageNamed:@"myImage.png"]];
myImage.opaque = YES; // explicitly opaque for performance 
[self.view addSubview:myImage]; 
[myImage release]; 

其中 myImage. png 是 png 格式的图像,您将其导入到资源文件夹中。

使用 Nib(Xib 文件):

  • 打开您的 .xib 文件。
  • 转到工具 ->图书馆。
  • 将一个 UIImageView 拖放到您的 .xib 上。
  • 打开 ImageView 的属性检查器(按 Cmd + 1)。
  • 您将获得一个 Image 属性。使用下拉列表从资源文件夹中设置所需的图像。
  • 就这样,你明白了。 :-)

Programmatically :

From http://www.iphoneexamples.com/:

CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect]; 
[myImage setImage:[UIImage imageNamed:@"myImage.png"]];
myImage.opaque = YES; // explicitly opaque for performance 
[self.view addSubview:myImage]; 
[myImage release]; 

Where myImage.png is an png format image which you will import to your resources folder.

Using Nib(Xib File):

  • Open your.xib file.
  • Go to Tools -> Library.
  • Drag and drop one UIImageView on your .xib.
  • Open Attribute Inspector of the ImageView(Press Cmd + 1).
  • You'll get one Image property. Set the image you want from your Resource folder using the drop-down list.
  • There you got it. :-)
∝单色的世界 2024-11-23 06:25:57
// First way     
myImage.image = [UIImage imageNamed:@"myImage.png"];  

// Second way  
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/myImage.png"];
myImage.image = [UIImage imageWithContentsOfFile:fullpath];  

查看 UIImageView 类参考

// First way     
myImage.image = [UIImage imageNamed:@"myImage.png"];  

// Second way  
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/myImage.png"];
myImage.image = [UIImage imageWithContentsOfFile:fullpath];  

Check out UIImageView class reference here

晨曦慕雪 2024-11-23 06:25:57

阅读 http://www.iphoneexamples.com/

CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"myImage.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];

Read http://www.iphoneexamples.com/

CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"myImage.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];
美胚控场 2024-11-23 06:25:57
UIImageView *imageView=[[UIImageView alloc] init];
[imageView setImage:[UIImage imageNamed:@"yourImage.png"]];

(如果您从 IB 创建了 imageView 并对其进行了outlet-ed,则忽略第一行)

UIImageView *imageView=[[UIImageView alloc] init];
[imageView setImage:[UIImage imageNamed:@"yourImage.png"]];

(If you have created imageView from IB and have outlet-ed it then ignore First Line)

梦里兽 2024-11-23 06:25:57

尝试使用:

imgView.image = [UIImage imageNamed:@"test.png"];

Try it using:

imgView.image = [UIImage imageNamed:@"test.png"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文