如何在ImageView中显示图像?

Aad*_*dil 2 iphone imageview

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

Cha*_*har 5

以编程方式:

来自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]; 
Run Code Online (Sandbox Code Playgroud)

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

使用Nib(Xib文件):

  • 打开your.xib文件.
  • 转到工具 - >库.
  • 在.xib上拖放一个UIImageView.
  • 打开ImageView的属性检查器(按Cmd + 1).
  • 你会得到一个Image属性.使用下拉列表从Resource文件夹设置所需的图像.
  • 你知道了吗 :-)