我在自定义 UITableViewCell
中有一个 UIImageView
,我想调整它的大小,我将它的 View 模式设置为 LEFT。要调整大小,我正在应用以下代码。
[cell.IBImage setFrame:CGRectMake(201,12,50,20)];
我的图像宽度是 100,我想将其减小到 50,但它仍然以 100 宽度显示我。如果我将 View 模式设置为 Scale To Fill
它工作正常,但我想将它的 View 模式设置为 LEFT。
完整方法 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);
关于iphone - UIImageView 设置框架 : not working in UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13890299/