2013-10-22 121 views
0

我在我的TableViewCell中有UIImageView。这个图像从例如苹果JSON解析。图像显示和所有工作完美,但我有问题调整这个图像的单元格。我试过但没有。我读了很多话题,人们也有同样的问题。我知道如何从URL制作图片的大小,但我已经解析图像并粘贴到cell.imageView。在TableViewCell中调整UIImageView的大小

所以,我从JSON形象代码:

[cell.imageView setImageWithURL:[NSURL URLWithString:[[array objectAtIndex:indexPath.row] objectForKey:@"artworkUrl60"]] placeholderImage:[UIImage imageNamed:@"noholder.png"]]; 

而这种代码我测试,但没有对图片的大小更改单元格

cell.imageView.frame=CGRectMake(50,50,300,300); 

如何在细胞改变图像的大小但没有URL链接。我必须从cell改变大小的图片。谢谢。

回答

1

您需要创建自定义单元格(至少对于iOS 7)。

这里有一个例子:
.h

@interface UITableViewImageCell : UITableViewCell { 
    CGRect     _imageViewFrame; 
} 

/** 
* To use default, set width and height to 0 
*/ 
@property(nonatomic, assign) CGRect    imageViewFrame; 
@end 

.m

@implementation UITableViewImageCell 
@synthesize imageViewFrame=_imageViewFrame; 

-(void)setImageViewFrame:(CGRect)imageViewFrame{ 
    _imageViewFrame = imageViewFrame; 
    [self setNeedsLayout]; 
} 

-(void)layoutSubviews{ 
    [super layoutSubviews]; 
    if (_imageViewFrame.size.width>0 && _imageViewFrame.size.height>0) { 
     self.imageView.frame = _imageViewFrame; 
    } 
} 

@end 

使用这个类,你就必须致电:

cell.imageViewFrame=CGRectMake(50,50,300,300); 
+0

非常感谢!这是完美的工作。 – Genevios