西贝了爷  

 前提:要注意图片的size和展示的图片view的size的大小. 假如图片高度50,展示图片view的高度30,拉伸会变成剪切.

    如果图片尺寸不对,可以用mac自带的图片编辑器修改大小:

    双击打开图片,选择左上角工具-->调整大小

        

    选择像素调整宽高

        

 

第1种:stretchableImageWithLeftCapWidth

             Width: 代表左边多少不拉伸

             height: 代表顶部多少不拉伸

             系统会根据我们设置的左边和顶部的距离, 自动计算出一块1*1的区域来拉伸(拉伸一小点区域)

        限制:顶部一半以上不拉伸

        image = [image stretchableImageWithLeftCapWidth:0 topCapHeight:image.size.height * 0.5];

  

 第2种:resizableImageWithCapInsets:UIEdgeInsetsMake

   指定图片的上下左右多少不能拉伸

            该方法默认是以平铺的方式拉伸(复制不能拉伸的区域直至铺满整个区域):UIImageResizingModeTile,

            另一种方法是直接拉伸一个能拉伸的区域 UIImageResizingModeStretch,

        image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(size.height * 0.5, size.width * 0.5, size.height * 0.5, size.width * 0.5)];

        或指定拉伸方法:

        image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 30) resizingMode:UIImageResizingModeStretch];

 

 第3种:使用编辑器      

         

     

     

    

 

posted on 2016-05-04 10:20  西贝了爷  阅读(477)  评论(0编辑  收藏  举报