UIImageview:
UIImageview可以在界面上显示图片或者动画,图片的来源可以是本地也可以是网络
1.初始化UIImageView
第一种加载图片的方法
UIImage*image=[UIImage imageNamed:@"3.jpg"];
UIImageView*imageview=[[UIImageView alloc]initWithImage:image ];
imageview.frame=CGRectMake(0, 0, 300, 300);
imageview.contentMode=UIViewContentModeTopRight;
第二种加载图片的方法,同伙路径
NSString*path=[[NSBundle mainBundle]pathForResource:@"1" ofType:@".png"];
//NSBundle是一个资源包
UIImage*image2=[UIImage imageWithContentsOfFile:path];
UIImageView*imageview2=[[UIImageView alloc]initWithImage:image2 ];
imageview.frame=CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
imageview.contentMode=UIViewContentModeScaleAspectFit;
第三种获得图片的方法(从网络上获取)
NSURL*imageURL=[NSURL URLWithString:@"http://img.alicdn.com/bao/uploaded/TB1jcB.IXXXXXbrXFXXSutbFXXX.jpg"];
UIImage*image3=[UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
UIImageView*imageview3=[[UIImageView alloc]initWithImage:image3 ];
imageview.frame=CGRectMake(100,100, 300, 100);
imageview.contentMode=UIViewContentModeScaleAspectFit;
//UIImageView的移动
imageview.transform=CGAffineTransformMakeTranslation(20, 20);
//UIImageView的旋转
imageview.transform=CGAffineTransformMakeRotation(1.57);//(填一个弧度)
//UIImageView动画
//(1)设置动画需要的图片
NSArray*imageArray=@[image,image2,image3];
//设置动画间隔的时间
imageview.animationDuration=0.5;
//传一个动画所需要的图片
imageview.animationImages=imageArray;
//设置动画执行的次数
imageview.animationRepeatCount=0;
//开始动画
[imageview startAnimating];
//显示多张图片
UIImage*image=[UIImage imageNamed:@"1.gif"];
UIImage*image1=[UIImage imageNamed:@"2.gif"];
UIImage*image2=[UIImage imageNamed:@"3.gif"];
NSArray*imageArray=@[image,image1,image2];
UIImageView*imageview6=[[UIImageView alloc]init];
imageview6.frame=CGRectMake(0,0,self.view.bounds.size.width, self.view.bounds.size.height);
imageview6.animationImages=imageArray;
//间隔时间
imageview6.animationDuration=0.2;
//设置动画执行的次数
imageview6.animationRepeatCount=1000;
//开始动画
[imageview6 startAnimating];