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

  • 相关阅读:
    Web开发框架 SSH 简介
    H5 性能调优 工具
    Mongodb性能调优
    峰Redis学习(4)Redis 数据结构(List的操作)
    峰Redis学习(3)Redis 数据结构(字符串、哈希)
    峰Redis学习(2)Jedis 入门实例
    峰Redis学习(1)Redis简介和安装
    使用jquery.mCustomScrollbar自定义滚动条(2)
    使用jquery.mCustomScrollbar自定义滚动条(1)
    jquery zTree异步搜索的例子--搜全部节点
  • 原文地址:https://www.cnblogs.com/mcj-coding/p/5107567.html
Copyright © 2011-2022 走看看