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]调用Restful Service 出现415 Unsupported Media Type的问题(Rest Request Header中的Content-Type问题)
用Chrome的插件Simple REST Client 调用POST的REST服务时,老是报415错误,如图. 一开始就以为是服务端的问题,各种google,百度,折腾了一下午未果. 晚上继续看,一 ...
- Beta Daily Scrum 第七天
[目录] 1.任务进度 2.困难及解决 3.燃尽图 4.代码check-in 5.总结 1. 任务进度 学号 今日完成 明日完成 612 app已完成 将APP交给客户使用 615 app已完成 将A ...
- bootstrap学习总结-03 常用标签1
1 显示段落 在HTML中,段落使用p标签包起来,重要的文字使用strong标签,em标签.<em> 标签告诉浏览器把其中的文本表示为强调的内容.对于所有浏览器来说,这意味着要把这段文字用 ...
- struts2文件目录结构
apps 文件夹包含了多个 example 示例应用的压缩包. docs 文件夹包含了 struts 官方的帮助文档. lib 文件夹包含了 struts 提供的类库 jar 包. src 文件夹包含 ...
- c语言程序
汇编语言嵌入到c语言中 #include<stdio.h> int main(void) { int a,b,c; a=4; b=5; _asm { mov eax,a; add eax, ...
- css010 css的transform transition和animation
css010 css的transform transition和animation 看着没有一个能想起他们是干什么的.. 1. Transform Transform(变形) r ...
- CSS3自适配手机屏幕
@media only screen and (max-width:350px){ .img{ width: 80px; height:70px; background-image: url(./im ...
- 导出excel失败,提醒提示加载类型库/DDL出错
导出excel失败,提醒提示加载类型库/DDL出错 www.MyException.Cn 发布于:2012-08-17 02:08:34 浏览:1538次 导出excel失败,提示提示加载 ...
- PHP ob系列函数详解
一. 相关函数简介: 1.Flush:刷新缓冲区的内容,输出. 函数格式:flush() 说明:这个函数经常使用,效率很高. 2.ob_start :打开输出缓冲区 函数 ...
- GLSL扩展预处理器(支持#include)
http://www.gamedev.net/topic/645610-do-you-extend-glsl/ https://github.com/ehsan/ogre/blob/master/Re ...