iphone - UIImageView 设置框架 : not working in UITableViewCell

标签 iphone objective-c ios uiimageview uiimage

我在自定义 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/

相关文章:

ios - Apptimize\Optimizely 如何在 iOS 上运行?

ios - GPUImage锁定 View

ios - 音频单元 v3 扩展不会出现在主机应用程序中

iphone - Asihttprequest 61 错误

ios - cloudkit 数据未显示在提交的应用程序 iOS 8.1 中

iphone - Facebook iOS 似乎在单击“确定”后返回应用程序时丢失了 session 您已经授权了应用程序

python - Socketswift 连接到特定 IP 地址超时

ios - "Unknown type name"使用 YACC 和 xcode

ios - 如何从另一个 Controller 打开嵌入式 Segue Controller ?

ios - ScrollView 动画不流畅(objective-C)