UIImageView 是iOS中?于显?图?的类,iOS中?乎所有看到的 图?,都是由这个类来显?的。
UIImageView 相当于一个相框,专门用作显示图片,可以存放一个图片或一组图片
UIImage 是图片对象
创建
1、从路径中获取
// 图??件路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"jpg"];
// 创建?个UIImage对象,使?initWithContentOfFile: ?法
UIImage *image = [UIImage imageWithContentsOfFile:path];
// 创建?个UIImageView对象,使?initWithImage: ?法
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(100, 100, 100, 100);
[self.view addSubview:imageView];
[imageView release];
2、一组图片
//做动态图
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 173, 173)];
//指定展示图片
// imageView.image = [UIImage imageNamed:@"dog-21(被拖移).tiff"];
NSMutableArray *mArr = [NSMutableArray arrayWithCapacity:0];
for (int i = 1; i < 30; i ++) {
//获取图片名称
NSString *picStr = [NSString stringWithFormat:@"dog-%d(被拖移).tiff",i];
//获取每一张图片对象
UIImage *image = [UIImage imageNamed:picStr];
[mArr addObject:image];
}
//指定做动画的所有图片
imageView.animationImages = mArr;
//指定动画时间、动画重复次数
imageView.animationDuration = 2;//时间间隔
imageView.animationRepeatCount = 0;//一直重复
//开启动画
[imageView startAnimating];
// [imageView stopAnimating];
[containerView addSubview:imageView];
[imageView release];
UIImageView
原文:http://www.cnblogs.com/Walking-Jin/p/5210778.html