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


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




经过查阅可知,应当使用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.


其传入的两个参数,一个参数代表图片左侧不需要拉伸的像素,第二个参数代表图片上端不需要拉伸的像素。调用该方法后效果如下:



你可能感兴趣的:(iOS开发,Objective-C)