一、UIImageView

     是iOS中⽤于显⽰图⽚的类,iOS中⼏乎所有看到的 图⽚,都是由这个类来显⽰的。

二、 一些具体的API

  1,创建静态图(需要先将图片加入到工程中)

     (1), UIImage *image = [UIImage imageNamed:@"4.jpeg"];

              如果图片名字以png结尾,可以只写图片名,否则写全称

 

    (2),UIImage *image = [UIImage imageWithContentsOfFile:@"/Users/lanou/Downloads/4.jpeg"];

           UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

             imageView.frame = CGRectMake(50, 100, 200, 200);// 如果不设置frame属性,则显示图片原来的大小

            imageView.userInteractionEnabled = YES; // imageView的用户交互默认是关闭的,需要时要设置为开

             [self.view addSubview:imageView];

             [imageView release];

    2,加载动态图

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 300, 300)];

    NSMutableArray *array = [NSMutableArray array];

    for (int i = 1; i <= 4; i ++) {

       UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"5%d(被拖移).tiff", i]];

       [array addObject:image];

    }

    imageView.animationImages = array;

    [imageView setAnimationDuration:0.5];// 播放一遍用的时  

   [imageView setAnimationRepeatCount:2];  // 设置循环播放次数

   [imageView startAnimating]; // 让动画开始动起来

  

   [self.view addSubview:imageView];

    

posted on 2015-08-25 23:02  竹间Code  阅读(90)  评论(0编辑  收藏  举报