Я также видел, что это также сделано (который я использую в UIButtons
для нормального и выделенного состояния, поскольку кнопки не подходят resize
). Благодарность идет тому, кем был первоначальный автор.
Сначала создайте пустой файл .h и .m с именами UIImageResizing.h
и UIImageResizing.m
// Put this in UIImageResizing.h
@interface UIImage (Resize)
- (UIImage*)scaleToSize:(CGSize)size;
@end
// Put this in UIImageResizing.m
@implementation UIImage (Resize)
- (UIImage*)scaleToSize:(CGSize)size {
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, size.width, size.height), self.CGImage);
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
@end
Включите этот файл .h в любой файл .m, в котором вы собираетесь использовать функцию и затем назовите это так:
UIImage* image = [UIImage imageNamed:@"largeImage.png"];
UIImage* smallImage = [image scaleToSize:CGSizeMake(100.0f,100.0f)];
I was able to find the answer here.
This thread contained this description for this error: This error may occur if an another request is made before the previous request of WebView is completed...
I worked around this by ignoring this error and letting the webview continue to load.
if ([error code] != NSURLErrorCancelled) {
//show error alert, etc.
}