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

来源:互联网 发布:sql修改字段数据类型 编辑:程序博客网 时间:2024/05/17 23:02

最近在看《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

0 0
原创粉丝点击