调整 UIImage 大小以发布到 Twitter Sheet-iOS [英] Resizing UIImage to post to Twitter Sheet- iOS

查看:19
本文介绍了调整 UIImage 大小以发布到 Twitter Sheet-iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调整图像大小以附加到 Twitter 表单.但我收到错误消息没有已知的选择器方法类imageWithImage: (UIImage)image ....""

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;

}

推荐答案

你在 UIImage 上调用了 imageWithImage:scaledToSize:,但是你的方法是在我假设的情况下实现的你的视图控制器.要使其工作,请将 twitterButtonPressed 更改为:

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)];
}

更好的解决方案是在 UIImage 上创建一个带有 imageWithImage:scaledToSize: 的类别.然后,当您导入此类别时,您不再需要视图控制器中的方法,您可以保持 twitterButtonPressed 原样,它会起作用.

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.

这篇关于调整 UIImage 大小以发布到 Twitter Sheet-iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆