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. 日历插件FullCalendar应用:(一)数据展现

    在博客园逛了很长时间了,它帮助我获得了很多知识,很感谢大家的分享,而自己呢,由于各种纠结一直没提笔写博客,直到我看到了这篇文章http://www.cnblogs.com/zhaopei/p/why_ ...

  2. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  3. bzoj 1711 [Usaco2007 Open]Dining吃饭&&poj 3281 Dining

    最大流. 这东西好像叫三分图匹配. 源点向每个食物点连一条容量为1的边. 每个饮料点向汇点连一条容量为1的边. 将每个牛点拆点,食物点向喜欢它的牛的入点连一条容量为1的边,牛的出点向它喜欢的饮料点连一 ...

  4. div+css:两个div并排等高 (table-cell)

    两个div并排等高 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  5. cocos2d-x-2.2.6 project-creator文件夹下python.bat

    @echo off set /p projectName=请输入项目名称: if "%projectName%"=="" goto inputError set ...

  6. UICollectionViewCell 网格显示数据

    using System; using System.Collections.Generic; using Foundation; using UIKit; namespace ddd { publi ...

  7. PHP之:序列化和反序列化-serialize()和unserialize()

    撰写日期:2016-7-7 10:56:40 参考PHP在线手册(php.net):http://php.net/manual/zh/function.serialize.php 1.序列化 seri ...

  8. Linux系统下设置环境变量

    例如我现在有一个软件understand代码审阅软件,现在我每次想要打开这个软件就要进到~/scitools/bin/linux32目录下,去执行可执行文件understand; 但每次都这样我会觉得 ...

  9. mac电脑http代理服务设置公司内网的相关配置

    哈喽,亲爱的小伙伴们 ,今天给大家分享一下公司内网配置 http代理服务设置及外网访问 ,<这是mac电脑的噢>  ===链接地址我的github项目   https://github.c ...

  10. ubuntu下非root用户下获得使用wireshark的权限

    在非root用户下不能使用wireshark用来抓包,所以需要进行以下操作: sudo groupadd wireshark sudo chgrp wireshark /usr/bin/dumpcap ...