UIImageView setFrame:不在UITableViewCell中工作

我有一个UIImageView在自定义的UITableViewCell ,我想调整它,我把它设置为左视图模式。 要resize,我正在应用下面的代码。

 [cell.IBImage setFrame:CGRectMake(201,12,50,20)]; 

我的图像宽度是100,我想减less到50,但它仍然显示我在100宽度。 如果我将视图模式设置为“ Scale To Fill它可以正常工作,但我希望将其视图模式设置为“左”。

完整的方法cellForRowAtIndexPath如下所示:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"DetailCell"; DetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"DetailCell" owner:self options:nil]; cell = (DetailCell *)[topLevelObjects objectAtIndex:0]; clsDetailResponse *Response = [self.Histories objectAtIndex:[indexPath row]]; [cell.IBUsernameLabel setText:[NSString stringWithFormat:@"%@ %@", Response.Firstname, Response.Lastname]]; [cell.IBImage setFrame:CGRectMake(201, 12, 50, 20)]; return cell; } 

你正在做的是调整imageView框而不是图像,所以你可以裁剪图像,只要你想,

 UIImage *ima = cell.image.image; CGRect cropRect = CGRectMake(0, 0, 50,20); CGImageRef imageRef = CGImageCreateWithImageInRect([ima CGImage], cropRect); [cell.image setImage:[UIImage imageWithCGImage:imageRef]]; CGImageRelease(imageRef); cell.image.frame=CGRectMake(10, 10, 50, 20); 

在DetailCell类中设置IBImage框架

 -(void)layoutSubviews: 

方法

将以下行添加到文件的所有者,以确保它知道如何响应framechanges。

  [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; [self setClipsToBounds:YES]; [self setAutoresizesSubviews:YES];