【问题标题】:How to keep image size in tableview consistent如何保持表格视图中的图像大小一致
【发布时间】:2014-04-27 09:50:44
【问题描述】:

我有一个显示图像的表格视图,问题是图像的质量和大小比例不同,所以当它们显示时,它们如下所示

我的调用代码如下所示

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        }
        cell.textLabel.font=[UIFont fontWithName:@"Arial Rounded MT Bold" size:20.0];
        cell.detailTextLabel.font=[UIFont fontWithName:@"Arial Rounded MT Bold" size:15.0];
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.detailTextLabel.textColor = [UIColor whiteColor];
        cell.contentView.backgroundColor = [UIColor clearColor];
        cell.textLabel.backgroundColor = [UIColor clearColor];
        cell.detailTextLabel.backgroundColor = [UIColor clearColor];
        cell.backgroundColor = [UIColor clearColor];
        cell.imageView.contentMode = UIViewContentModeScaleAspectFill;

        Pupils *aPupil = [ArrayOfDisplayIDs objectAtIndex:indexPath.row];


        cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", aPupil.firstname,aPupil.secondname];
        cell.detailTextLabel.numberOfLines = 3;
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%@: %@      Gender: %@ \n%@: %@   \n%@: %@", @"Class",aPupil.Class, aPupil.Gender, @"Date of Birth" ,aPupil.DOB, @"Date of Enrolment" ,aPupil.DateofEntry];
        cell.imageView.image = aPupil.picture;
    return cell;
 }

无论如何,我怎样才能使这些照片保持相同的大小。

所以图片大小相同,高度相同,宽度相同,或者文字都从一条直线开始,只是为了整洁。

谢谢

【问题讨论】:

  • 你能定义“相同大小”吗?目前这两个图像都被限制为填充单元格的高度,你想要实现什么?添加您希望最终结果的模型可能会有所帮助。

标签: objective-c ipad uitableview


【解决方案1】:

创建一个自定义 UITableviewCell 并更改 layoutSubviews 方法以设置单元格的 imageView.frame 就像在这个答案中一样:

https://stackoverflow.com/a/4866205/1014164

【讨论】:

    猜你喜欢
    • 2015-07-08
    • 2017-10-10
    • 1970-01-01
    • 2016-05-18
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    • 2011-11-25
    • 2022-01-03
    相关资源
    最近更新 更多