iOS中image拉伸操作的三种方式
方式一
UIImage *image = [UIImage imageNamed:@"chat_send_nor"];
// 拉伸处理(说明需要保护的区域)
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 30) resizingMode:UIImageResizingModeStretch];
方式二
UIImage *image = [UIImage imageNamed:@"chat_send_nor"];
// 这种方式的图片拉伸只需要传入左侧和顶部,苹果内部就会自动计算出底部和右侧的间距,计算方式见下面的注释;
image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
// left
// top
// width
// height
// right = width - left - 1;
// 1 = width - left - right;
// bottom = height - top - 1;
// 1 = height - top - bottom;
方式三
- 直接对Images.xcassets里面的图片进行操作:见下图
- 选择Horizental and Vertical选项
- 在通过[UIImage imageNamed:]方法获得的该图片就会是自动拉伸之后的效果了.
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。