iOS7 tableview cell.imageview额外填充?

Ale*_*son 5 uitableview ios7

我有一个tableview,可以在iOS 6中完美呈现并且已经这么做了多年.在同一个tableview中的iO7中,在cell.imageview的任一侧,它在下面显示的每个图像的两侧大约5mm处添加一些额外的填充,从而将我的cell.textLabel.text进一步向右移动.我怎么能删除这个我似乎找不到这个问题的答案?

iOS图片

小智 9

在iOS7的UITableViewCell的预定义的属性imageView朝着正确的缩进15pt默认.
这与以下属性 无关UITableViewCell

indentationLevel
indentationWidth
shouldIndentWhileEditing
separatorInset
Run Code Online (Sandbox Code Playgroud)

因此,创建自己的自定义UITableViewCell是克服它的最佳方法.
根据Apple的说法,有两种很好的方法可以做到:

如果您希望单元格具有不同的内容组件并将它们布置在不同的位置,或者您希望单元格具有不同的行为特征,则有两种选择:

  • 将子视图添加到单元格的内容视图中.
  • 创建UITableViewCell 的自定义子类.

解:

由于您不喜欢子类化UITableViewCell,因此您可以选择添加自定义子视图.
只需创建自己的图像视图和文本标签,然后通过代码或故事板添加它们.例如

//caution: simplied example
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //get the cell object
    static NSString *CellIdentifier = @"myCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    //create your own labels and image view object, specify the frame
    UILabel *mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 220.0, 15.0)];
    [cell.contentView addSubview:mainLabel];

    UILabel *secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 20.0, 220.0, 25.0)];
    [cell.contentView addSubview:secondLabel];

    UIImageView *photo = [[UIImageView alloc] initWithFrame:CGRectMake(225.0, 0.0, 80.0, 45.0)];
    [cell.contentView addSubview:photo];

    //assign content
    mainLabel.text = @"myMainTitle";
    secondLabel.text = @"mySecondaryTitle";
    photo.image = [UIImage imageNamed:@"myImage.png"];
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

需要注意的是一个预定义的UITableViewCell内容属性:cell.textLabel,cell.detailTextLabelcell.imageView不变所以他们会提醒nil并不会显示.


参考:

仔细查看表视图单元格 https://developer.apple.com/Library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1

希望这有帮助!


nul*_*ull 6

我可能遇到了同样的问题,唯一适用于我的是设置图像框架:

cell.imageView.frame = CGRectMake( 0, 0, 50, 55 );
Run Code Online (Sandbox Code Playgroud)

如果你是细胞的子类,那么最好做:

- (void) layoutSubviews
{
    [super layoutSubviews];
    self.imageView.frame = CGRectMake( 0, 0, 50, 55 );
}
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢,但设置框架对我来说仍然没有任何区别.我仍然在桌子的两侧填充填充:-(.我想我可以将细胞子类化,但看起来像是一把锤子来破解坚果! (6认同)