深入理解iOS API系列(二)UIImage的resizableImageWithCapInsets:resizingMode:

最近在看《programming iOS8》,看到第二章的“可调整大小的images”。实现这个效果的方法我们并不陌生,可以参看MJ的博客http://blog.csdn.net/q199109106q/article/details/8615661 。当然我们要讨论的不是API的变动,我们更关注UIImageResizingMode的影响。它有两个枚举量UIImageResizingModeTile和  UIImageResizingModeStretch。我觉得作者对于这个变量的效果的描述还是非常到位的。


UIImageResizingModeTile

The interior rectangle of the inset area is tiled (repeated) in the interior; each edgeis formed by tiling the corresponding edge rectangle outside the inset area. The fourcorner rectangles outside the inset area are drawn unchanged.

UIImageResizingModeStretch


The interior rectangle of the inset area is stretchedonceto fill the interior; each edgeis formed by stretching the corresponding edge rectangle outside the inset areaonce. The four corner rectangles outside the inset area are drawn unchanged.

对于Tile方式的,我们可以把一张图分解为3部分,一个是inset确定的内部区域,一个是四个端帽,还有一个是剩余部分,剩余部分刚好是与inset的四条毗邻的四个矩形。Tile后的效果你可以认为是拼积木,先inset平铺若干个,然后放上4个端帽,最后平铺剩余部分。类似地,对于Stretch方式的,只要将前者中的“平铺”改成“拉伸”就行了。顺便说下,常用的拉伸策略是把几乎是原始图片的一半作为capinset,仅仅在中间留出1到2像素来填充整个内部。


现在再来看看http://www.cnblogs.com/heyonggang/archive/2013/12/19/3482733.html,你应该能够理解作者的意思了。其他的博文:

http://www.cnblogs.com/zhangqifeng/p/4004433.html

http://blog.sina.com.cn/s/blog_884e78b2010150b3.html

http://duchengjiu.iteye.com/blog/1901288


严重参考:

http://www.th7.cn/Program/IOS/201405/203735.shtml

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值