iOS7 tableview cell.imageview额外填充? [英] iOS7 tableview cell.imageview extra padding?

查看:122
本文介绍了iOS7 tableview cell.imageview额外填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a tableview which renders perfectly in iOS 6 & has done so for years. In iO7 in the same tableview either side of the cell.imageview its adding some extra padding approx 5mm either side of each image shown below thus moving my cell.textLabel.text further to the right. How would I remove this I cant seem to find the answer anywhere to this question?

推荐答案

在iOS7中, UITableViewCell 的预定义属性 imageView 默认情况下向右缩进15pt

这有以下 UITableViewCell 属性

In iOS7, the UITableViewCell's predefined property imageView is indented towards right by 15pt by default.
And this has nothing to do with the following UITableViewCell properties

indentationLevel
indentationWidth
shouldIndentWhileEditing
separatorInset

因此创建自己的自定义 UITableViewCell 是克服它的最好方法。

根据Apple ,有两种很好的方法可以做到:

Therefore creating your own custom UITableViewCell is the best way to overcome it.
According to Apple, there are 2 good ways to do it:


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

If you want the cell to have different content components and to have these laid out in different locations, or if you want different behavioral characteristics for the cell, you have two alternatives:


  • 将子视图添加到单元格的内容视图中。

  • 创建一个UITableViewCell的自定义子类

  • Add subviews to a cell’s content view.
  • Create a custom subclass of UITableViewCell.






解决方案:



由于您不喜欢子类化 UITableViewCell ,因此您可以选择添加自定义子视图。

只需创建自己的子视图图像视图和文本标签,并通过代码或故事板添加它们。例如


Solution:

As you don't prefer subclassing UITableViewCell, so adding custom subviews is your choice.
Simply creates your own image view and text labels, and add them through code or through storyboard. e.g.

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

请注意,作为预定义的 UITableViewCell 内容属性: cell.textLabel cell.detailTextLabel cell.imageView 未触及,因此他们会提醒 nil 并且不会显示。

Note that as the predefined UITableViewCell content properties: cell.textLabel, cell.detailTextLabel and cell.imageView are untouched so they will remind nil and will not be shown.

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

希望这有帮助!

这篇关于iOS7 tableview cell.imageview额外填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆