UIImageview学习

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,100300, 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];


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值