Objective c 使用YouTube JSON编辑的SDWebImage从URL调整下载的图像大小

Objective c 使用YouTube JSON编辑的SDWebImage从URL调整下载的图像大小,objective-c,ios5,Objective C,Ios5,我使用SDWebImage从youtube JSON web服务下载缩略图,以便在表视图单元格中设置它们。问题是下载的图像是120x90,对于我的需要来说太大了,因为我想把它放在75x75的UIImageView中。虽然图像缓存在占位符中,但它们看起来是正确的,但一旦缓存完成,它们的大小将为120x90。我尝试了setContentMode:UIViewContentModeScaleToFill,但它不起作用,所以我不知道如何解决这个问题 NSString *path= [thumbnail

我使用SDWebImage从youtube JSON web服务下载缩略图,以便在表视图单元格中设置它们。问题是下载的图像是120x90,对于我的需要来说太大了,因为我想把它放在75x75的UIImageView中。虽然图像缓存在占位符中,但它们看起来是正确的,但一旦缓存完成,它们的大小将为120x90。我尝试了setContentMode:UIViewContentModeScaleToFill,但它不起作用,所以我不知道如何解决这个问题

NSString *path= [thumbnail valueForKey:@"sqDefault"];

        [cell.imageView setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

        [cell.imageView setContentMode:UIViewContentModeScaleToFill];

        CALayer * l = [cell.imageView layer];

        [l setMasksToBounds:YES];

        [l setCornerRadius:5.0];
非常感谢

编辑:

我已在自定义单元格扩展类中设置内容模式:

newsCell.m

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.Image   setContentMode:UIViewContentModeScaleToFill];

    }


    return self;
}
下面是单元格创建代码:

多媒体

 newsCell *cell = [self.tableView 
                          dequeueReusableCellWithIdentifier:@"news"];

        if (cell == nil) {
            cell = [[newsCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:@"news"];
        }
问题是,如果从未调用cell==nil,因为第一条语句正在创建cell,因此不会调用initWithStyle,也不会设置内容模式,但如果删除第一条语句,则不会创建cell。我不知道如何管理它


谢谢

试试这两个选项,看看哪一个更适合您的需要:

UIViewContentModeScaleAspectFit
UIViewContentModeAspectFill

如果这些不起作用,我猜这是因为UITableViewCell正在UIImageView上设置contentMode-在这种情况下,您应该创建UITableViewCell的子类,其中包含设置了正确contentMode的UIImageView。然后,您可以在UITableView中使用自定义UITableViewCell子类。

试试这两个选项,看看哪一个更适合您的需要:

UIViewContentModeScaleAspectFit
UIViewContentModeAspectFill

如果这些不起作用,我猜这是因为UITableViewCell正在UIImageView上设置contentMode-在这种情况下,您应该创建UITableViewCell的子类,其中包含设置了正确contentMode的UIImageView。然后可以在UITableView中使用自定义UITableViewCell子类。

在自定义单元格类中设置表图像视图的自定义大小

    - (void)layoutSubviews {  
    [super layoutSubviews];  
    self.imageView.frame = CGRectMake(5,5,40,32.5);  
    float limgW =  self.imageView.image.size.width;  
    if(limgW > 0) {  
        self.textLabel.frame = CGRectMake(55,self.textLabel.frame.origin.y,self.textLabel.frame.size.width,self.textLabel.frame.size.height);  
        self.detailTextLabel.frame = CGRectMake(55,self.detailTextLabel.frame.origin.y,self.detailTextLabel.frame.size.width,self.detailTextLabel.frame.size.height);  
    }  
}  

有关详细信息,请在表图像视图的自定义单元格类中设置其自定义大小

    - (void)layoutSubviews {  
    [super layoutSubviews];  
    self.imageView.frame = CGRectMake(5,5,40,32.5);  
    float limgW =  self.imageView.image.size.width;  
    if(limgW > 0) {  
        self.textLabel.frame = CGRectMake(55,self.textLabel.frame.origin.y,self.textLabel.frame.size.width,self.textLabel.frame.size.height);  
        self.detailTextLabel.frame = CGRectMake(55,self.detailTextLabel.frame.origin.y,self.detailTextLabel.frame.size.width,self.detailTextLabel.frame.size.height);  
    }  
}  

有关更多详细信息,它们不起作用,但Xcode声称使用UIViewContentModeScaleAspectFit而不是UIViewContentModeAspectFit。谢谢,我添加了一些可能对你有帮助的信息。迈克尔,我按照你的指示做了,我编辑了这个问题,所以我在初始化自定义单元格时遇到了问题。很多人感谢它们不起作用,但Xcode声称使用UIViewContentModeScaleAspectFit而不是UIViewContentModeAspectFit。谢谢,我添加了一些可能对你有帮助的信息。迈克尔,我按照你的指示做了,我编辑了这个问题,所以我在初始化自定义单元格时遇到了问题。非常感谢