原理基本和安卓的.9图片类似。不过iOS是直接设定4个方向的距离inset,拉伸里面的小区域。

这里设置上下左右4个方向的距离都是30,然后看下面的图:

iOS图片部分区域拉伸(聊天气泡的实现)

拉伸的区域也就是上图红色小方块的区域。

图片拉伸的几个方法:

代码的方式:UIImage *newImage = [image resizableImageWithCapInsets:edgeInsets];

UIEdgeInsets edgeInsets = UIEdgeInsetsMake(top, left, bottom, right);
UIImageResizingMode mode = UIImageResizingModeStretch;
// 拉伸图片
UIImage *newImage = [image resizableImageWithCapInsets:edgeInsets resizingMode:mode];

但上面的代码方式始终不够简洁明了。感觉拖泥带水。所以引出下面的方法。

如图设置需要拉伸的区域即可:

iOS图片部分区域拉伸(聊天气泡的实现)

点击蓝色圆圈的show slicing有惊喜。

然后你就可以在xib文件里,使用UIImageview控件测试查看你的拉伸区域设置是否正确啦。

相关文章:

  • 2022-02-07
  • 2021-06-22
  • 2021-12-15
  • 2021-08-25
  • 2022-12-23
  • 2021-10-12
猜你喜欢
  • 2021-12-15
  • 2022-12-23
  • 2021-05-19
  • 2021-11-13
  • 2021-07-03
  • 2022-12-23
相关资源
相似解决方案