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

小智 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.detailTextLabel和cell.imageView是不变所以他们会提醒nil并不会显示.
希望这有帮助!
我可能遇到了同样的问题,唯一适用于我的是设置图像框架:
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)
| 归档时间: |
|
| 查看次数: |
12398 次 |
| 最近记录: |