一、图片拉伸
对于一些动态展示,如果底部有背景框的话,那么这个背景框需要动态的调整大小,这就涉及到图片的拉伸
- (void)bgView:(UIImageView *)imageView
{
CGFloat top =20; //顶端盖高度
CGFloat bottom =10; // 底端盖高度
CGFloat left =20; // 左端盖宽度
CGFloat right =20; //有端盖宽度
UIEdgeInsets insets =UIEdgeInsetsMake(top, left, bottom, right);
// 不要忘记最后将改变后的图片赋给 imageView.image 否则相当于什么都没做
imageView.image = [imageView.imageresizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
}
二、 图片缩放
// image 为要缩放的图片, scaleSize为要缩放的比例,比如0.5
- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize, image.size.height*scaleSize));
[image drawInRect:CGRectMake(0,0, image.size.width*scaleSize, image.size.height*scaleSize)];
UIImage *scaledImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}