问题
I am trying to resize my image in order to attach to twitter sheet. But I am getting error as "No known class for selector method "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;
}
回答1:
You call imageWithImage:scaledToSize:
on UIImage
, but your method is implemented in what I assume is your view controller. To make it work, change twitterButtonPressed
to:
- (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)];
}
A better solution would be to create a category on UIImage with imageWithImage:scaledToSize:
in it. Then, when you import this category, you don't need the method in your view controller anymore and you can leave twitterButtonPressed
as-is and it'll work.
来源:https://stackoverflow.com/questions/16485895/resizing-uiimage-to-post-to-twitter-sheet-ios