图片填充模式
一、常用填充模式
-
UIViewContentModeScaleToFill 变形塞满;
-
UIViewContentModeScaleAspectFit 等比例不超出显示,大概率会有部分边缘空白;
-
UIViewContentModeScaleAspectFill 原图比例显示,大概率图片会溢出;
二、拉伸
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight
leftCapWidth: 水平拉伸;拉伸区域为 x = leftCapWidth + 1个像素;
topCapHeight:竖直拉伸;拉伸区域为 y = topCapHeight + 1个像素;
样例代码
UIImageView *imgV1 = [[UIImageView alloc]initWithFrame:CGRectMake(20, 80, 340, 700)]; imgV1.backgroundColor = [UIColor orangeColor]; UIImage *img1 = [UIImage imageNamed:@"1"]; img1 = [img1 stretchableImageWithLeftCapWidth:img1.size.width*0.5 topCapHeight:img1.size.height*0.5]; imgV1.image = img1; [self.view addSubview:imgV1];
此文章为个人笔记,方便自己以及有需要的朋友查看,转载请注明出处!