iOS开发_设置图片拉伸方式

1、只拉伸中间的 1 * 1 的区域

// 设置的区域为不拉伸(保护)的部分,自动计算右侧和下侧保护部分的大小:
// rightCapWidth = width - leftCapWidth - 1
// bottomCapHeight  = height - topCapHeight - 1
image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5
                                   topCapHeight:image.size.height * 0.5];
  • 聊天框设置拉伸方式前后拉伸效果
    __

2、拉伸指定的区域

// 设置的区域为不拉伸(保护)的部分
// 拉伸模式:
// UIImageResizingModeTile         平铺,默认
// UIImageResizingModeStretch      直接拉伸
// 以默认平铺模式拉伸
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 30)];

// 以指定拉伸模式拉伸
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 30)
                              resizingMode:UIImageResizingModeStretch];
posted @ 2022-11-10 17:52  CH520  阅读(116)  评论(0编辑  收藏  举报