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> 模拟器应 ...
随机推荐
- 两种遍历list
li=[[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]]s=0for i in range(0,5): for j in ran ...
- 错误:违反并发性: DeleteCommand 影响了预期 1 条记录中的 0 条
在access的mdb数据库动态更新的过程中,遇到了DeleteCommand出现DBConcurrencyException异常,错误:违反并发性: DeleteCommand 影响了预期 1 条记 ...
- OI省选算法汇总
copy from hzwer @http://hzwer.com/1234.html 侵删 1.1 基本数据结构 1. 数组 2. 链表,双向链表 3. 队列,单调队列,双端队列 4. 栈,单调栈 ...
- jsp上传图片实时显示
jsp代码 <div class="form-group" id="caseIma"> <label class="control- ...
- PHP 进程详解
.note-content { font-family: "Helvetica Neue", Arial, "Hiragino Sans GB", STHeit ...
- Fixing DSDT
https://clover-wiki.zetam.org/Fixing-DSDT#dsdt-mask_fixdisplay_0100-bit-8
- [教程] [授权翻译] 使用补丁修改DSDT/SSDT [DSDT/SSDT综合教程]
[教程] [授权翻译] 使用补丁修改DSDT/SSDT [DSDT/SSDT综合教程] http://bbs.pcbeta.com/viewthread-1571455-1-1.html [教程] [ ...
- canvas刮刮乐效果(pc端&H5、zepto-touchmove)
一.html <div id="canvasArea" style="width:300px;height:200px;position:relative;&quo ...
- EFCore教程
https://docs.microsoft.com/en-us/ef/core/modeling/alternate-keys aspnet core 教程 https://docs.microso ...
- 怎么把本地项目和远程git仓库相连通
1. 打开在你的项目文件夹,输入下面的命令 git init 输完上面的命令,文件夹中会出现一个.git文件夹,如下图所示,其他的的文件也会出现蓝色小问号的标志 2. 添加所有文件 git add . ...