- 如果想要拉伸一个图片,直接拉伸的话,图片有透明的区域会拉伸变形,需要设置保护的区域方法可以分为两种
- 通过代码
UIImageView *imageView =[[UIImageView alloc]init];
imageView.frame = CGRectMake(10, 10, 200, 100);
[self.view addSubview:imageView];
//加载原图
UIImage *image =[UIImage imageNamed:@"chat_send_press_pic"];
//拉伸处理 UIEdgeInsetsMake 需要保护的区域
// image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 30) resizingMode:UIImageResizingModeStretch];
// imageView.image = image;
/**
* 一个图片有上下左右位置,stretchableImageWithLeftCapWidth方法是算出1*1的像素不保护
* leftCapWidth :width - left - right - 1
* topCapHeight :height - top - bottom - 1
*/
image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
imageView.image = image;
-
在Assset文件中设置