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定义的类方法 上节介绍了类方法定义的语法以及各种使用的场景,本节结合上节的知识具体举例说明相关内容. 一. 案例说明 本节定义的一个 ...
随机推荐
- alertDialog创建登陆界面,判断用户输入
alertDialog创建登陆界面,需要获取用户输入的用户名和密码,获取控件对象的时候不能像主布局文件那样获得, 需要在onClickListener中获取,代码如下: public boolean ...
- CF 702B Powers of Two(暴力)
题目链接: 传送门 Devu and Partitioning of the Array time limit per test:3 second memory limit per test: ...
- HDU 1535 Invitation Cards(最短路 spfa)
题目链接: 传送门 Invitation Cards Time Limit: 5000MS Memory Limit: 32768 K Description In the age of te ...
- 在Nginx中部署基于IP的虚拟主机
一.虚拟主机概念 虚拟主机是在网络服务器上划分出一定的磁盘空间供用户放置站点.应用组件等,提供必要的站点功能.数据存放和传输功能.所谓虚拟主机,也叫"网站空间", 就是把一台运行在 ...
- python学习笔记-(二)python入门
1.第一个python程序 1.1 直接打印输出 打开cmd,输入python进入到python交互式环境:(看到>>>是在Python交互式环境下:) 在python交互环境下输入 ...
- rem自适应布局的回顾总结
使用rem实现自适应布局,应该算是当前移动前端的一大趋势,有些人对此还有点迷惑,搞不懂rem是如何实现自适应布局,如何根据设计稿来调整rem的值?rem布局如何用雪碧背景图片?rem一定要加载JS吗? ...
- Xcode卡顿解决方案
1.禁用indexing 在终端(terminal) 输入 defaults write com.apple.dt.XCode IDEIndexDisable 并重启Xcode. (不是大神勿用哈,附 ...
- Apache配置--用户认证(针对目录访问)-update2015-05-02
通过Apache配置可以限制用户对目录的访问,会弹出像phpadmin一样的登陆框. ========================================================= ...
- SCWS分词扩展在WINDOWS下的安装方法
安装之前先确认您是否拥有主机的安装权限,否则无法进行安装,安装步骤如下: 1. 根据您当前用的 PHP 版本,下载相应已编译好的 php_scws.dll 扩展库. 目前支持以下版本 [PHP-4 ...
- git diff
git diff 工作区与暂存区的差别 git diff -cached / git diff -staged 暂存区与版本库的差别 git diff HEAD 工作区与版本库的差别 git d ...