1

我正在尝试调整图像大小以附加到 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;

}
4

1 回答 1

1

您调用imageWithImage:scaledToSize:on 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保持原样,它会起作用。

于 2013-05-10T16:40:36.757 回答