码迷,mamicode.com
首页 > 其他好文 > 详细

6. UIImageView 的使用

时间:2016-01-06 23:25:37      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

1. UIImageView 的认识

QQ:853740091

UIImageView 继承UIView,通过他的名字我们也可以看出这个是用来显示图片的

 

2. 使用方法

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

    // 背景颜色

    imageView.backgroundColor = [UIColor redColor];

    // 设置显示的图片

    imageView.image = [UIImage imageNamed:@"picheng.jpg"];

    // UIImageView的填充模式

    // 占满

    imageView.contentMode = UIViewContentModeScaleToFill;

    // 按原比例填充

    imageView.contentMode = UIViewContentModeScaleAspectFit;

    // 按比例填满

    imageView.contentMode = UIViewContentModeScaleAspectFill;

       [self.view addSubview:imageView];

 

 还有一种比较常用的实例化imageView的方式

    UIImageView *imageViewOne = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"picheng.jpg"]];

    imageViewOne.frame = CGRectMake(100, 100, 200, 200);

    [self.view addSubview:imageViewOne];

 

加载网上的图片(比较卡,因为在主线程中完成)

UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];

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

 //   设置圆角

    imageView.layer.masksToBounds = YES;

    imageView.layer.cornerRadius = 10;

  //   设置边框颜色和大小

    imageView.layer.borderColor = [UIColor orangeColor].CGColor;

    imageView.layer.borderWidth = 2;

3. 播放图片

// 创建UIImageView

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 120, 300, 400)];

    imageView.tag = 119;

    [self.view addSubview:imageView];

    

    // 设置图片数组

    NSMutableArray *arrayM = [[NSMutableArray alloc] init];

    for (int i = 0 ; i < 75; i ++) {

        // 获取图片的名称

        NSString *imageName = [NSString stringWithFormat:@"img_%d",i];

        // 获取image对象

        UIImage *image = [UIImage imageNamed:imageName];

        // 把对象放进数组

        [arrayM addObject:image];

    }

    

    // 设置图片数组

    imageView.animationImages = arrayM;

    

    // 设置播放时间

    imageView.animationDuration = 5;

    

    // 设置播放次数(0 无限循环播放)

    imageView.animationRepeatCount = 1;

    

    // 开始播放

    // [imageView startAnimating];

   

简单实例代码: https://github.com/mcj122755/UIImageViewDemo2.git

 

6. UIImageView 的使用

标签:

原文地址:http://www.cnblogs.com/mcj-coding/p/5107567.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!