- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Set the data for this cell:
cell.textLabel.text = [namesArray objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor grayColor];
cell.textLabel.font = [UIFont fontWithName:@"Trebuchet MS" size:14];
cell.textLabel.textAlignment = UITextAlignmentLeft;
cell.imageView.image = [UIImage imageNamed:[imagesArray objectAtIndex:indexPath.row ]];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 5, 5)];
imgView.image = [UIImage imageNamed:[imagesArray objectAtIndex:indexPath.row ]];
cell.imageView.image = imgView.image;
[cell.imageView setFrame:CGRectMake(0, 0, 55, 55)];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
return cell;
}
여기서는 사용 TableView
하지 않지만 UITableViewCell
에서 이미지 크기를 조정하고 싶습니다 TableView
. 인터넷에서 많은 예제를 살펴 보았지만 어떻게 작동하는지 이해하지 못합니다 TableView
.에서 크기를 조정할 수 없습니다 . 누군가 그것을 작동시키는 방법을 설명 할 수 있습니까? [cell.imageView setFrame : CGRectMake (0, 0, 55, 55)]; 작동하지 않는다
여기에 자르기 및 이미지 크기 조정 논리를 넣고 요구 사항에 따라 사용합니다.
잘린 이미지 가져 오기 :
UIImage *croppedImg = nil;
CGRect cropRect = CGRectMake(AS YOu Need); // set frame as you need
croppedImg = [self croppIngimageByImageName:self.imageView.image toRect:cropRect];
UIImage
( 당신이 원하는 이미지 크기로 ) 반환하는 다음 메서드
- (UIImage *)croppIngimageByImageName:(UIImage *)imageToCrop toRect:(CGRect)rect
{
//CGRect CropRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height+15);
CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
}
여기에서 위의 방법으로 반환되는 Croped Image를 얻습니다.
또는 크기 조정
또한 크기 조정을 위해 이미지의 특정 높이 및 너비 와 함께 다음 방법을 사용하십시오 .
+ (UIImage*)resizeImage:(UIImage*)image withWidth:(CGFloat)width withHeight:(CGFloat)height
{
CGSize newSize = CGSizeMake(width, height);
CGFloat widthRatio = newSize.width/image.size.width;
CGFloat heightRatio = newSize.height/image.size.height;
if(widthRatio > heightRatio)
{
newSize=CGSizeMake(image.size.width*heightRatio,image.size.height*heightRatio);
}
else
{
newSize=CGSizeMake(image.size.width*widthRatio,image.size.height*widthRatio);
}
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
이 메서드는 원하는 특정 크기 로 NewImage를 반환 합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다