zoukankan      html  css  js  c++  java
  • 6. UIImageView 的使用

    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

  • 相关阅读:
    python之+=与+(转载)
    python之上下文管理器与contextlib
    python之类中的super函数
    python之__dict__与dir(转载)
    python多继承之c3算法(转载)
    python之比较is与==(转载)
    python之鸭子类型
    python之抽象基类
    raindi python魔法函数(一)之__repr__与__str__
    Win7系统无法记住网络访问的凭据怎么办?
  • 原文地址:https://www.cnblogs.com/mcj-coding/p/5107567.html
Copyright © 2011-2022 走看看