UIImageView的简单使用
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 //将图片转化为UIImage对象 4 //png格式不需要加扩展名,其它格式图片需要 5 UIImage* image1 = [UIImage imageNamed:@"a"]; 6 UIImage* image2 = [UIImage imageNamed:@"b"]; 7 8 UIImageView* imageV = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 70)]; 9 [self.view addSubview:imageV]; 10 //设置背景颜色 11 imageV.backgroundColor = [UIColor orangeColor]; 12 //设置显示的图片 13 imageV.image = image1; 14 //改变图片填充方式 15 //UIViewContentModeScaleAspectFit,等比例缩放,图片不变形 16 //UIViewContentModeScaleAspectFill,等比例填充,填满 17 imageV.contentMode = UIViewContentModeScaleAspectFit; 18 //切除超出部分 19 // imageV.clipsToBounds = YES; 20 21 //设置高亮图片 22 imageV.highlightedImage = image2; 23 imageV.highlighted = YES; 24 25 26 //动画数组 27 UIImageView* animateImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 190)]; 28 [self.view addSubview:animateImageView]; 29 //创建动画数组 30 NSMutableArray* animateImages = [[NSMutableArray alloc] init]; 31 32 for (int i = 1; i < 22; i++) { 33 //记得加扩展名(.jpg) 34 NSString* imageName = [NSString stringWithFormat:@"%d.jpg",i]; 35 UIImage* image = [UIImage imageNamed:imageName]; 36 [animateImages addObject:image]; 37 } 38 //设置需要播放的动画(图片数组) 39 animateImageView.animationImages = animateImages; 40 //设置动画时间 41 animateImageView.animationDuration = 2; 42 //设置重复次数(0是一直重复) 43 animateImageView.animationRepeatCount = 0; 44 45 //开始动画 46 [animateImageView startAnimating]; 47 48 49 }
posted on 2015-06-21 16:17 Andy_Capricorn 阅读(188) 评论(0) 编辑 收藏 举报