我正在尝试调整图片大小以便附加到Twitter表格。但我收到的错误是“没有已知的选择器方法类”imageWithImage: (UIImage)image...."
“
- (void)twitterButtonPressed {
UIImage *iconImage=[UIImage imageNamed:@"male_small_0.png"];
// I am having problem in the following line
UIImage *iconImage2=[UIImage imageWithImage:iconImage scaledToSize:CGSizeMake(73.0, 73.0)];
}
-(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
答案 0 :(得分:1)
您在imageWithImage:scaledToSize:
上呼叫UIImage
,但您的方法是在我假设的视图控制器中实现的。要使其有效,请将twitterButtonPressed
更改为:
- (void)twitterButtonPressed {
UIImage *iconImage=[UIImage imageNamed:@"male_small_0.png"];
// I am having problem in the following line
UIImage *iconImage2=[self imageWithImage:iconImage scaledToSize:CGSizeMake(73.0, 73.0)];
}
更好的解决方案是在UIImage上创建一个带有imageWithImage:scaledToSize:
的类别。然后,当您导入此类别时,您不再需要视图控制器中的方法,您可以保持原样twitterButtonPressed
并且它将起作用。