Question

I have UIImageView in my TableViewCell. This Image parse from for example apple JSON. Image show and all work perfectly but i have problem with resize this image in cell. I tried this but nothing. I read many topics and peoples have the same problem. I know how to make size for picture from URL but i have parse image and paste to cell.imageView.

So my code of image from JSON:

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

And this code i tested but nothing to change in size of picture in cell

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

How to change the size of image in cell but without URL link. I must change size picture from cell.Thanks.

Was it helpful?

Solution

You'll need to create a custom cell (at least for iOS 7).

Here's a sample:
.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

Using this class, you'd have to call:

cell.imageViewFrame=CGRectMake(50,50,300,300);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top