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
6. UIImageView 的使用的更多相关文章
- AFNetworking 3.0 源码解读(十)之 UIActivityIndicatorView/UIRefreshControl/UIImageView + AFNetworking
我们应该看到过很多类似这样的例子:某个控件拥有加载网络图片的能力.但这究竟是怎么做到的呢?看完这篇文章就明白了. 前言 这篇我们会介绍 AFNetworking 中的3个UIKit中的分类.UIAct ...
- UI控件(UIImageView)
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; image1_ = [UIImage imageNa ...
- iOS--使用UIImageView进行GIF动图播放
大家好,好久没有跟新了.其实也就昨天到今天的时间. 前言:实际上,GIF动图文件中包含了一组图片及其信息数组,这些信息数据记录着这一组图片中各张图片的播放时长等信息,我们可以将图片和这些信息或取出来, ...
- UIImageView 自带动画+N张图片实现很炫的动画
gitHub上又看到个很炫的动画:https://github.com/MartinRGB/GiftCard-iOS 看了看他的代码,发现核心动画(就是把按钮包装成一个礼物盒)其实很简单,就是把一 ...
- UIImageView
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. /***** ...
- IOS开发之Bug--关于UIImageView的使用
这里是遇到的一个关于使用UIImageView的小bug,bug就是加载不出来图片. 原因:如果图片资源是jpg文件,如果代码没有加后缀.jpg就会出现不加载出来的情况: 添加上.jpg就能加载出来了 ...
- UIScrollView,UIPageControl,UIImageView 实现图片轮播的效果
上一篇博客介绍了如何将XCode创立的项目提交到Git版本控制,这次就直接做一个图片轮播的展示demo,刚好可以把UIScrollView.UIPageControl.UIImageView这三个控件 ...
- iOS中UIImageView的填充模式
UIImageView的填充模式 属性名称 imageV.contentMode枚举属性: @"UIViewContentModeScaleToFill", // 拉伸自适应填满整 ...
- NSBundle控件和UIImageView和UIButton区别
1.NSBundle 1> 一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹 2> 利用mainBundle就可以访问软件资源包中的任何资源 3> 模拟器应 ...
随机推荐
- javascript随机打乱数组
var arr=[]; ;i<;i++){ arr[i]=i; } arr.sort(function(){ return 0.5 - Math.random() }) var str=arr. ...
- [DUBBO]Dubbo控制台查看方法
1.dubbo控制台安装方法网上较多,例如转载http://dtbuluo.com/blog/archives/37 2.dubbo控制台查看 由于我们组是开发安装的dubbo.zookeeper等等 ...
- gprs/gsm 在linux下的应用
之前有篇随笔整理了一种在裸机下用状态机+超时的机制来操作gprs/gsm,linux下就不需要了,本身有完善的调度机制,在等待的流程中直接sleep就行了. 下面是飞凌OK6410下的 demo, 其 ...
- Java集合之HashSet
1.HashSet概述: HashSet实现Set接口,由哈希表(实际上是一个HashMap实例)支持.它不保证set 的迭代顺序:特别是它不保证该顺序恒久不变.此类允许使用null元素.HashSe ...
- runtime-对成员变量操作应用之归档和返归档
为了实现归档和返归档,我们要让被归档对象的类接受NSCoding协议并且实现协议里的两个方法 - (void)encodeWithCoder:(NSCoder *)aCoder; - (nullabl ...
- Hadoop基础——第一弹:Hadoop介绍
一.基础 1.了解Java.Linux操作系统相关知识 2.如需精进,应为水平要达到一定标准,能够阅读国外相关技术网站,eg:http://hadoop.apache.org/ 二.什么是Hadoop ...
- 常用linux 命令 -字符串相关
参考网络文章,个人工作总结 题记:一般对字符串的操作有以下几种:求长度,截取字符串,拼接字符串,找字符串中某个字符的索引 1 expr 命令 1.1 定义 man 手册 Print the value ...
- codeforces 459E
codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabyte ...
- C和指针 第十六章 标准函数库 本地跳转setjmp.h
setjmp和longjmp提供一种类似goto语句的机制,但它的作用域不局限于同一个函数的作用域之内.这些函数可以用于深层次的嵌套函数调用链. int setjmp(jmp_buf state); ...
- Mongodb系统管理员权限设置
管理员账号无法执行show dbs .show collections Js代码 { "_id" : ObjectId("52a82bb26cea234c4deb06 ...