UI第四节——UIImageView详解
- (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详解的更多相关文章
- UI第六节——UINavigationController 详解
1. UINavigationController 是一个容器类.里面盛放的是UIViewController. 容器的意思是,如果你不放入UIViewController,里面就是空的,什么也没有. ...
- UI第七节——UISlider详解
- (void)viewDidLoad { [super viewDidLoad]; // 实例化UISlider,高度对外观没有影响 UISlider *slider = [[UISlider al ...
- ElasticSearch第四步-查询详解
ElasticSearch系列学习 ElasticSearch第一步-环境配置 ElasticSearch第二步-CRUD之Sense ElasticSearch第三步-中文分词 ElasticSea ...
- J2EE进阶(四)Spring配置文件详解
J2EE进阶(四)Spring配置文件详解 前言 Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程 ...
- [转]Linux服务器上11种网络连接状态 和 TCP三次握手/四次挥手详解
一.Linux服务器上11种网络连接状态: 图:TCP的状态机 通常情况下:一个正常的TCP连接,都会有三个阶段:1.TCP三次握手;2.数据传送;3.TCP四次挥手. 注:以下说明最好能结合”图:T ...
- TCP三次握手与四次挥手详解
目录 TCP三次握手与四次挥手详解 1.TCP报文格式 2.TCP三次握手 3.TCP四次挥手 4.为什么建立连接需要三次握手? 5.为什么断开连接需要四次挥手? 6.为什么TIME_WAIT状态还需 ...
- 第7.20节 案例详解:Python抽象类之真实子类
第7.20节 案例详解:Python抽象类之真实子类 上节介绍了Python抽象基类相关概念,并介绍了抽象基类实现真实子类的步骤和语法,本节结合一个案例进一步详细介绍. 一. 案例说明 本节定义 ...
- 第7.18节 案例详解:Python类中装饰器@staticmethod定义的静态方法
第7.18节 案例详解:Python类中装饰器@staticmethod定义的静态方法 上节介绍了Python中类的静态方法,本节将结合案例详细说明相关内容. 一. 案例说明 本节定义了类Sta ...
- 第7.16节 案例详解:Python中classmethod定义的类方法
第7.16节 案例详解:Python中classmethod定义的类方法 上节介绍了类方法定义的语法以及各种使用的场景,本节结合上节的知识具体举例说明相关内容. 一. 案例说明 本节定义的一个 ...
随机推荐
- [JavaEE] NIO与IO的区别
nio是new io的简称,从jdk1.4就被引入了.现在的jdk已经到了1.6了,可以说不是什么新东西了.但其中的一些思想值得我来研究.这两天,我研究了下其中的套接字部分,有一些心得,在此分享. 首 ...
- ensure LANG and/or LC_* environment variables are set correctly
Looks like your locale settings are broken or non-existent on that VM, or at least that session on t ...
- Yocto开发笔记之《错误记录》(QQ交流群:519230208)
QQ群:519230208,为避免广告骚扰,申请时请注明 “开发者” 字样 ============================================== 提问: 1. 怎样修改linu ...
- WinForm------TreeList实现鼠标经过节点背景色改变
转载: http://www.cnblogs.com/zfanlong1314/archive/2012/06/26/2564124.html
- angularjs笔记(三)
AngularJS API 7.其他一些常用指令,布尔类型的指令也可以用表达式 (1).数组索引$index <!DOCTYPE html> <html> <head&g ...
- js随机从数组中取出几个元素
JS如何从一个数组中随机取出一个元素或者几个元素. 假如数组为 var items = ['1','2','4','5','6','7','8','9','10']; 1.从数组items中随机取出一 ...
- CodeForces 710CMagic Odd Square(经典-奇数个奇数&偶数个偶数)
题目链接:http://codeforces.com/problemset/problem/710/C 题目大意:输入一个奇数n,则生成n*n矩阵,要求矩阵的行.列还有斜着,所有元素之和为奇数. 解题 ...
- FBX Transformation
2010: http://download.autodesk.com/us/fbx/20102/FBX_SDK_Help/index.html?url=WS1a9193826455f5ff3913a1 ...
- php Hash Table(二) Hash函数
哈希表最关键的几个方面有: 通过key访问(通过哈希函数计算出key) 映射到数据结构中(哈希表本身的存储结构) 映射的处理(冲突或者碰撞检测和处理函数) 理解PHP的哈希算法 一般来说对于整形索引进 ...
- Autofac和DynamicProxy2搭配实现Aop动手训练
http://www.cnblogs.com/zhengwl/p/5433181.html Aop含义:aspect-oriented programming 实现工具介绍 Autofac是一个比较流 ...