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 的使用的更多相关文章

  1. AFNetworking 3.0 源码解读(十)之 UIActivityIndicatorView/UIRefreshControl/UIImageView + AFNetworking

    我们应该看到过很多类似这样的例子:某个控件拥有加载网络图片的能力.但这究竟是怎么做到的呢?看完这篇文章就明白了. 前言 这篇我们会介绍 AFNetworking 中的3个UIKit中的分类.UIAct ...

  2. UI控件(UIImageView)

    @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; image1_ = [UIImage imageNa ...

  3. iOS--使用UIImageView进行GIF动图播放

    大家好,好久没有跟新了.其实也就昨天到今天的时间. 前言:实际上,GIF动图文件中包含了一组图片及其信息数组,这些信息数据记录着这一组图片中各张图片的播放时长等信息,我们可以将图片和这些信息或取出来, ...

  4. UIImageView 自带动画+N张图片实现很炫的动画

    gitHub上又看到个很炫的动画:https://github.com/MartinRGB/GiftCard-iOS   看了看他的代码,发现核心动画(就是把按钮包装成一个礼物盒)其实很简单,就是把一 ...

  5. UIImageView

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. /***** ...

  6. IOS开发之Bug--关于UIImageView的使用

    这里是遇到的一个关于使用UIImageView的小bug,bug就是加载不出来图片. 原因:如果图片资源是jpg文件,如果代码没有加后缀.jpg就会出现不加载出来的情况: 添加上.jpg就能加载出来了 ...

  7. UIScrollView,UIPageControl,UIImageView 实现图片轮播的效果

    上一篇博客介绍了如何将XCode创立的项目提交到Git版本控制,这次就直接做一个图片轮播的展示demo,刚好可以把UIScrollView.UIPageControl.UIImageView这三个控件 ...

  8. iOS中UIImageView的填充模式

    UIImageView的填充模式 属性名称 imageV.contentMode枚举属性: @"UIViewContentModeScaleToFill", // 拉伸自适应填满整 ...

  9. NSBundle控件和UIImageView和UIButton区别

    1.NSBundle 1> 一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹 2> 利用mainBundle就可以访问软件资源包中的任何资源 3> 模拟器应 ...

随机推荐

  1. 架构师养成记--6.单例和多线程、ThreadLocal

    一.ThreadLocal 使用wait/notify方式实现的线程安全,性能将受到很大影响.解决方案是用空间换时间,不用锁也能实现线程安全. 来看一个小例子,在线程内的set.get就是thread ...

  2. 魅族mx4 pro连电脑,adb无法获取devices信息解决

    根据 flyme 的文档: K:\MX4 USB Reference Manual\简体\MX4_ADB_参考说明书.txt 操作如下: 二.Windows XP中文环境1.  建立或修改C:\Doc ...

  3. WEB – Architecture

  4. HDU 3669 Cross the Wall

    题目大意 给定 \(N\) 个矩形的宽和高, \((h_1, w_1), (h_2, w_2), \dots, (h_n w_n)\) . 现需要确定 \(k\) (\(k \le K\), \(K\ ...

  5. Theano Graph Structure

    Graph Structure Graph Definition theano's symbolic mathematical computation, which is composed of: A ...

  6. UVA 11235Frequent values(RMQ)

    训练指南P198 题意:给出一个非降序排列的整数数组a1, a2…… an,你的任务是对于一系列询问(i,j),回答ai, ai+1 ……aj 中出现的次数最多的次数 这题不仅学到了rmq的应用还学到 ...

  7. C#基础强化-进程操作

    using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using S ...

  8. Angularjs兼容IE

    http://www.tuicool.com/articles/EJv6riY http://www.angularjs.cn/A00v http://www.cnblogs.com/ahl5esof ...

  9. CentOS 7.0安装配置Vsftp服务器

    一.配置防火墙,开启FTP服务器需要的端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...

  10. 耗电—Android

    Android应用耗电分析与优化 http://sanwen8.cn/p/297Ut7b.html http://www.cnblogs.com/kobe8/p/3819305.html 有效控制An ...