- (void)viewDidLoad {

    // super调用是必须的
[super viewDidLoad]; UIImage *image = [UIImage imageNamed:@"q.jpg"]; // 实例化UIImageView,并设置其位置
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 30, 335, 200)];
imageView.backgroundColor = [UIColor redColor]; // 设置UIImageView的图片
imageView.image = image; //需要设置图片 UIImage 第一种:[imageView setImage:[UIImage imageNamed:@"1.jpeg"]]; //第二种:
NSString *filePath=[[NSBundle mainBundle] pathForResource:@"1" ofType:@"jpeg"];
UIImage *images=[UIImage imageWithContentsOfFile:filePath];
//[imageView setImage:images]; //第三种:
NSData *data=[NSData dataWithContentsOfFile:filePath];
UIImage *image2=[UIImage imageWithData:data];
[imageView setImage:image2]; // 设置圆角 imageView.layer.masksToBounds = YES; imageView.layer.cornerRadius = 10; // 设置边框颜色和大小 imageView.layer.borderColor = [UIColor orangeColor].CGColor; imageView.layer.borderWidth = 2; /**这三个模式是会缩放的,其他模式都不会缩放*/
// UIViewContentModeScaleToFill 缩放去填充整个View的大小
// UIViewContentModeScaleAspectFill 保持Image的宽高比,去缩放填充整个View的大小
// UIViewContentModeScaleAspectFit 保持Image的宽高比,去缩放以适应View的大小 // UIView的内容显示的模式
imageView.contentMode = UIViewContentModeTopRight; // 剪切掉超出View的大小的内容
imageView.clipsToBounds = YES; // 把UIImageView添加到self.view上
[self.view addSubview:imageView]; //播放一系列的图片,
NSMutableArray *animationImages = [[NSMutableArray alloc] init];
for (int i=1; i<=12; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"player%d", i]];
[animationImages addObject:image];
} UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 240, 335, 200)]; // 动画的一组图片
animationImageView.animationImages = animationImages; // 播放一组动画的执行时间,单位是秒
animationImageView.animationDuration = 2.0f; // 动画的重复次数,0是无限重复,默认是0
animationImageView.animationRepeatCount = 0; // 播放动画
[animationImageView startAnimating]; // N秒之后,执行代码
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6* NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [animationImageView stopAnimating]; }); [self.view addSubview:animationImageView];
}

PS:  frame: 该view在父view坐标系统中的位置和大小。(参照点是,父亲的坐标系统)
        bounds:该view在本地坐标系统中的位置和大小。(参照点是,本地坐标系统,就相当于ViewB自己的坐标系统,以0,0点为起点)
        center:该view的中心点在父view坐标系统中的位置和大小。(参照电是,父亲的坐标系统)

记住哦!!!!

如果对你有帮助,请关注我哦!

UI第四节——UIImageView详解的更多相关文章

  1. UI第六节——UINavigationController 详解

    1. UINavigationController 是一个容器类.里面盛放的是UIViewController. 容器的意思是,如果你不放入UIViewController,里面就是空的,什么也没有. ...

  2. UI第七节——UISlider详解

    - (void)viewDidLoad { [super viewDidLoad]; // 实例化UISlider,高度对外观没有影响 UISlider *slider = [[UISlider al ...

  3. ElasticSearch第四步-查询详解

    ElasticSearch系列学习 ElasticSearch第一步-环境配置 ElasticSearch第二步-CRUD之Sense ElasticSearch第三步-中文分词 ElasticSea ...

  4. J2EE进阶(四)Spring配置文件详解

    J2EE进阶(四)Spring配置文件详解 前言 Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程 ...

  5. [转]Linux服务器上11种网络连接状态 和 TCP三次握手/四次挥手详解

    一.Linux服务器上11种网络连接状态: 图:TCP的状态机 通常情况下:一个正常的TCP连接,都会有三个阶段:1.TCP三次握手;2.数据传送;3.TCP四次挥手. 注:以下说明最好能结合”图:T ...

  6. TCP三次握手与四次挥手详解

    目录 TCP三次握手与四次挥手详解 1.TCP报文格式 2.TCP三次握手 3.TCP四次挥手 4.为什么建立连接需要三次握手? 5.为什么断开连接需要四次挥手? 6.为什么TIME_WAIT状态还需 ...

  7. 第7.20节 案例详解:Python抽象类之真实子类

    第7.20节 案例详解:Python抽象类之真实子类 上节介绍了Python抽象基类相关概念,并介绍了抽象基类实现真实子类的步骤和语法,本节结合一个案例进一步详细介绍. 一.    案例说明 本节定义 ...

  8. 第7.18节 案例详解:Python类中装饰器@staticmethod定义的静态方法

    第7.18节 案例详解:Python类中装饰器@staticmethod定义的静态方法 上节介绍了Python中类的静态方法,本节将结合案例详细说明相关内容. 一.    案例说明 本节定义了类Sta ...

  9. 第7.16节 案例详解:Python中classmethod定义的类方法

    第7.16节  案例详解:Python中classmethod定义的类方法 上节介绍了类方法定义的语法以及各种使用的场景,本节结合上节的知识具体举例说明相关内容. 一.    案例说明 本节定义的一个 ...

随机推荐

  1. UEditor上传图片到七牛云储存(c#)

    我们的网站一般放在虚拟空间或者服务器上,图片如果存在本地目录,会占用很多空间和流量,还增加了负担,好的办法是把图片存放到云储存服务里面,平时用url去拿 云储存:普遍说又拍云和七牛比较好,看到七牛免费 ...

  2. As环境下添加android support library依赖库

    2015年的google大会上,google发布了新的Android Support Design库的新组件之一,以此来全面支持Material Design 设计风格的UI效果,为了可以使用这些新颖 ...

  3. 解决Eclipse 项目报错:Unbound classpath container

    Eclipse出现下面两条报错: The project cannot be built until build path errors are resolved HelloWord Unknown ...

  4. System.IO.Directory.Delete目录删除

    在程序运行的时候,如果直接获取一个目录路径,然后执行删除(包括子目录及文件): System.IO.Directory.Delete(path,true); 或者 System.IO.Director ...

  5. 捉襟见肘之UIViewAnimationOptions

    [UIView animateWithDuration:duration delay:0.0f options:(curve << | UIViewAnimationOptionBegin ...

  6. mysql-python

    sudo pip install MySQL-python centos安装 python-dev包提示No package python-dev available: 出现此问题的原因是python ...

  7. CentOS7安装Nginx并部署

    服务器IP是192.168.36.136 1.直接yum install nginx即可 2.主配置文件是/etc/nginx/下的nginx.conf,另外一个是/etc/nginx/conf.d/ ...

  8. 初识Hadoop一,配置及启动服务

    一.Hadoop简介: Hadoop是由Apache基金会所开发的分布式系统基础架构,实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS:Hadoo ...

  9. JavaWeb学习笔记——javabean与表单

  10. Unity Shader Lab

    http://docs.unity3d.com/460/Documentation/Manual/SL-BuiltinValues.html http://docs.unity3d.com/Manua ...