您的位置:首页 > 其它

图片拉伸处理:stretchableImageWithLeftCapWidth方法的使用

2015-03-16 13:02 531 查看
在制作退出按钮的时候,如果直接使用如上的素材,会发现图片拉伸变形,达不到想要的效果,失败的效果如下:

经过查阅可知,应当使用stretchableImageWithLeftCapWidth的方法对图片进行处理后再使用,苹果官方对该方法的解释如下:

Creates and returns a new image object with the specified cap values.

During scaling or resizing of the image, areas covered by a cap are not scaled or resized. Instead, the 1-pixel wide area not covered by the cap in each direction is what is scaled or resized. This technique is often used to create variable-width
buttons, which retain the same rounded corners but whose center region grows or shrinks as needed.
其传入的两个参数,一个参数代表图片左侧不需要拉伸的像素,第二个参数代表图片上端不需要拉伸的像素。调用该方法后效果如下:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: