2013-10-22 2 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 링크가 없습니다. 나는 세포에서 크기 그림을 바꾸어야한다. 고마워.

답변

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