美文网首页
resizeWithImage来使得聊天气泡图片边缘不拉伸

resizeWithImage来使得聊天气泡图片边缘不拉伸

作者: 里克尔梅西 | 来源:发表于2020-09-03 15:19 被阅读0次

方法为:

- (UIImage *)resizeWithImage:(UIImage *)image{
    CGFloat top = image.size.height/2.0;
    CGFloat left = image.size.width/2.0;
    CGFloat bottom = image.size.height/2.0;
    CGFloat right = image.size.width/2.0;
    return [image resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right)resizingMode:UIImageResizingModeStretch];
}
  • UIImageResizingModeStrech:拉伸模式,通过拉伸UIEdgeInsets指定的矩形区域来填充图片
  • UIImageResizingModeTile:平铺模式,通过重复显示UIEdgeInsets指定的矩形区域来填充图片

resizableImageWithCapInsets有四个值上下左右

image

上下左右的值定义了受保护区域,能被拉伸的地方是中间区域,一般我们都设成中心点为了安全。

参考文章:https://www.jianshu.com/p/7200a2b7b25a

相关文章

网友评论

      本文标题:resizeWithImage来使得聊天气泡图片边缘不拉伸

      本文链接:https://www.haomeiwen.com/subject/lkznsktx.html