UIImage学习
UIImage
A UIImage
object is a high-level way to display image data. You can create images from files, from Quartz image objects, or from raw image data you receive. The UIImage
class also offers several options for drawing images to the current graphics context using different blend modes and opacity values.
一个 UIImage 对象是一个高级别的方式来显示图像数据。你可以从文件,从Quartz图像对象,创建的图像或您收到从原始图像数据。UIImage 类还提供了用于绘制图像到使用不同的混合模式和不透明度值的当前图形上下文的几个选项。
官方推荐用UIImage加载图片尺寸是应该小于1024*1024,否则会有问题
1.普通加载一张图片
根据名字加载一张图片到UIImage;
UIImage *firstImg = [UIImage imageNamed:@"bg"];此时UIImage并未从文件中加载,因为他还没有显示到View中。当第一次显示到View中后,开始从路径中解码图片到内存中,并且缓存一份。
2.指定拉伸区域加载一张图片
这张图片做较大的UIImageView的背景时,如果不处理会是这样
很明显变形了用这个方法处理一下就ok了
– resizableImageWithCapInsets:resizingMode:
– resizableImageWithCapInsets:
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
[self.view addSubview:imageView]; UIImage *firstImg = [UIImage imageNamed:@"bg"]; // imageView.image = firstImg;
self.firstImageView.image = [firstImg resizableImageWithCapInsets:UIEdgeInsetsMake( , , , ) resizingMode:UIImageResizingModeStretch];
效果如图:
CapInsets:传入四个角的不改变的区域
resizingMode:模式。是一个系统枚举,如果图片的中间是一样的 两种模式随便选择
typedef NS_ENUM(NSInteger, UIImageResizingMode) {
UIImageResizingModeTile, //表示平铺充满 如果要是图片中间有文字会看到重复
UIImageResizingModeStretch,//表示拉伸充满 如果要是图片中间有文字会看到拉伸
};
3.动画加载一组图片
+ (UIImage *)animatedImageNamed:(NSString *)name duration:(NSTimeInterval)duration //加载同名的一组image,逐个显示成动画,注意这一组图片的名字一样,假如图片的名字为image0,image1,image2,image3...等,name只需要填@"image"即可。
+ (UIImage *)animatedImageWithImages:(NSArray *
)images
duration:(NSTimeInterval
)duration//动画逐个显示NSArray里面的图片 //下面这两个方法是
animatedImageNamed:duration: 和第二条中方法的结合
+ (UIImage *)animatedResizableImageNamed:(NSString *
)name
capInsets:(UIEdgeInsets
)capInsets
duration:(NSTimeInterval
)duration
+ (UIImage *)animatedResizableImageNamed:(NSString *
)name
capInsets:(UIEdgeInsets
)capInsets
resizingMode:(UIImageResizingMode
)resizingMode
duration:(NSTimeInterval
)duration
UIImage学习的更多相关文章
- UIImage学习笔记
UIImage是什么 用来管理APP里的图片资源,可以用来表示设备支持的图片资源,不仅仅是jpg和png. UIImage是immutable的,因此也是线程安全的. iOS支持的所有的图片格式 链接 ...
- github源码学习之UIImage+YYWebImage
UIImage+YYWebImage是YYWebImage(https://github.com/ibireme/YYWebImage)中的一个分类,这个分类封装了一些image常用的变化方法,非常值 ...
- UI基础:UIButton.UIimage 分类: iOS学习-UI 2015-07-01 21:39 85人阅读 评论(0) 收藏
UIButton是ios中用来响应用户点击事件的控件.继承自UIControl 1.创建控件 UIButton *button=[UIButton buttonWithType:UIButtonTyp ...
- iOS UIImage 图片局部拉伸的一些学习要点
之前 做纯色局部拉伸 通过 top bottom left right 相交的阴影拉伸 屡试不爽 实施方法: imageView.image = [[UIImage imageNamed: @&q ...
- iOS学习-压缩图片(改变图片的宽高)
压缩图片,图片的大小与我们期望的宽高不一致时,我们可以将其处理为我们想要的宽高. 传入想要修改的图片,以及新的尺寸 -(UIImage*)imageWithImage:(UIImage*)image ...
- iOS阶段学习第34天笔记(UI小组件 UISegment-UISlider-UIStepper-UIProgressView-UITextView介绍)
iOS学习(UI)知识点整理 一.UI小组件 1.UISegmentedControl 分段选择器 实例代码 - (void)viewDidLoad { [super viewDidLoad]; / ...
- iOS阶段学习第33天笔记(自定义标签栏(UITabBar)介绍)
iOS学习(UI)知识点整理 一.自定义标签栏 1.方法一 单个创建标签栏 #import "AppDelegate.h" #import "SecondViewCont ...
- 【swift学习笔记】三.使用xib自定义UITableViewCell
使用xib自定义tableviewCell看一下效果图 1.自定义列 新建一个xib文件 carTblCell,拖放一个UITableViewCell,再拖放一个图片和一个文本框到tableviewc ...
- Coding源码学习第二部分(FunctionIntroManager.m)
接上篇.上篇有一个细节忘了写,在Coding_iOS-Info.plist 里面添加了一个key 是 Status bar is initially hidden Value 是 YES,在appl ...
随机推荐
- [官方软件] Easy Sysprep v4.3.29.602 【系统封装部署利器】(2016.01.22)--skyfree大神
[官方软件] Easy Sysprep v4.3.29.602 [系统封装部署利器](2016.01.22) Skyfree 发表于 2016-1-22 13:55:55 https://www.it ...
- Security » Authorization » 基于视图的授权
View Based Authorization¶ 基于视图的授权 44 of 46 people found this helpful Often a developer will want to ...
- 搭建IONIC开发环境
1.准备工作 下载 Node.js(下载包),WebStorm(IDE,编写代码,浏览器调试),JDK(webstorm 运行环境),Android SDK (Android编译) 2.配 ...
- Ubuntu Server 配置网络
------------------ Ubuntu 14.04 x86_64 ----------------- 设置静态IP:vi /etc/network/interfaces. 然后再编辑 ...
- JAVA08多态之课程问题解决
课后作业一:接口多态:使用接口代替抽象基类 1.源代码: package zoo4; import java.util.Vector; public class Zoo2 { public stati ...
- cocos2dx 3.1获取系统当前时间
std::string Tools::getcurrTime() { #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATF ...
- Web应用安全十大主动安全措施
这几天有空参加了360主办的第一届互联网安全大会(ISC 2013),除了现场看到FREEBUF现场微博号发的众多妹子之外,也听到了很多有趣的议题,比如TK分享的通过网络运营商缓存服务器偷渡,只需一台 ...
- action和servlet的关系
在struts2.0中,可以通过ServletActionContext.getRequest()获取request对象. 在action的方法中return一个字符串,该字符串对应struts. ...
- qq客服代码
http://shang.qq.com/v3/widget.html <a target="_blank" href="http://wpa.qq.com/msgr ...
- C——没有bool的C语言?
bool static my_var_initialized = false; 偶然写出了这样一句C代码,环境是visual studio 2012,工程是Compile as C的,竟然报了好几个错 ...