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

  • 相关阅读:
    牛客网·剑指offer 从尾到头打印链表(JAVA)
    牛客网·剑指offer 替换空格(JAVA)
    简单的用户登录后台程序编写
    牛客网&剑指offer 二维数组中的查找(JAVA)
    洛谷 P1603 斯诺登的密码(JAVA)
    【回溯法】八皇后问题(递归和非递归)
    如何使用SecureCRT让Vim有颜色?
    js 转base64字符串为文件
    springboot 测试类
    oracle 登录、重启服务
  • 原文地址:https://www.cnblogs.com/mcj-coding/p/5107567.html
Copyright © 2011-2022 走看看