【问题标题】:Positioning UIImageViews in UITableView cells在 UITableView 单元格中定位 UIImageViews
【发布时间】:2012-04-15 04:49:38
【问题描述】:

我正在创建一个缩略图网格,使用一个 UITableView,每个单元格显示 3 个。在这个阶段,我只是尝试放置 3 个静态图像以获得正确的位置/大小。但我无法控制缩略图的位置和大小。这是我的一张缩略图的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// after getting cell..

UIImage *image = [UIImage imageNamed:@"placeholder.png"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50.0, 0.0, 85.0, 85.0)];
imageView = [[UIImageView alloc] initWithImage:image];        
[cell addSubview:imageView];

return cell;

}

通过在 UIImageView 中设置来控制图像的位置和大小,我的理解是否正确?

感谢您的帮助。

【问题讨论】:

    标签: ios uitableview uiimageview cgrect


    【解决方案1】:

    您需要在视图中缩放图像:

    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    [imageView setFrame:CGRectMake(50.0, 0.0, 85.0, 85.0)];
    [imageView setContentMode:UIViewContentModeScaleAspectFill];
    [cell addSubview:imageView];
    

    【讨论】:

    • 谢谢。我尝试添加您的行 (setContentMode),但没有效果。我应该在情节提要中检查什么吗?
    • 您正在初始化两个不同的 imageView,请稍后编辑。
    • 天啊.. 是时候休息一下了。非常感谢,成功了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    • 2011-10-17
    相关资源
    最近更新 更多