如何设置默认图像

时间:2011-12-03 17:22:16

标签: iphone ios xcode

在我点击图像以拉动相机之前,我想在图像视图上设置一个默认图像,显示http://www.inc.com/images/avatar/default1.gif以通知图像视图中的人物图像。

执行此程序的最佳方法是什么?

最好的问候。

2 个答案:

答案 0 :(得分:1)

UIImageView *theImageView;
//assuming that's the declaration in your header

//make sure default1.gif is inside your application bundle

//copied into the resources folder of your xcode project

//this code goes into your -viewDidLoad method

theImageView.image = [UIImage imageNamed:@"default1.gif"];

答案 1 :(得分:1)

如果您使用的是UIImageView,首先要使用此代码创建UIImage对象

UIImage *defaultImage = [UIImage imageNamed:@"default.png"];

然后将它传递给UIImageView对象,如果它是你的视图控制器的属性,你可以使用它(imageView是UIImageView的变量名)

self.imageView.image = defaultImage;

如果要在视图控制器中实例化新的UIImageView,可以使用此

UIImageView *imageView = [[UIImageView alloc] initWithImage:defaultImage];
相关问题