UIImage有一个名为'stretchchableImageWithLeftCapWidth'的方法,可以水平缩放图像而不缩放'大写'。
有没有办法垂直地做到这一点?甚至水平和垂直?
SDK没有向我显示任何可能执行此操作的方法。谷歌也没有提供任何帮助,但也许我正在寻找错误的词语。
答案 0 :(得分:3)
实际方法是
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight
它支持任何方向的拉伸(不缩放,两者是不同的概念)。
如果只想垂直拉伸,则将leftCapWidth
设置为零,仅水平拉伸,然后将topCapHeight
设置为零。并且在两个方向上伸展都适当地设置。
答案 1 :(得分:0)
您可以使用此功能在水平轴和垂直轴上根据自己的喜好缩放UIImage。
我将此方法放在UIImage类别中。它简化了代码。
+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}