如何使tableview中的图像大小保持一致

时间:2014-04-27 09:50:44

标签: objective-c ipad uitableview

我有一个显示图像的tableview,问题是图像具有不同的质量和尺寸比率,因此当它们显示时,它们显示如下enter image description here

我调用此代码的代码如下所示

- (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;
 }

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

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

感谢

1 个答案:

答案 0 :(得分:0)

创建自定义UITableviewCell并更改layoutSubviews方法以设置单元格imageView.frame,如下所示:

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