iOS 9 UITableView单元格的文本标签不是UITableView的全宽 [英] iOS 9 UITableView cell's text label not the full width of the UITableView

查看:150
本文介绍了iOS 9 UITableView单元格的文本标签不是UITableView的全宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自更新到iOS 9以来,iPad格局中的表格视图单元格不再在单元测试中拉伸表格的整个宽度。

Since updating to iOS 9, table view cell's in iPad landscape no longer stretch the full width of the table in my unit tests.

我的测试是一个简单的表格在最后拍摄快照。

My test is a simple table that takes a snapshot at the end.

- (void)testTableSize{
    UIViewController *viewController = [[UIViewController alloc] init];
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0,viewController.view.bounds.size.width, viewController.view.bounds.size.height) style:UITableViewStylePlain];

    tableView.dataSource = self;
    tableView.delegate = self;

    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
    [viewController.view addSubview:tableView];

    ASCSnapshotVerifyViewiPad([viewController view]);
}

此示例的单元格非常简单

The cells are very simple for this example

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

// Configure the cell...
cell.textLabel.backgroundColor = [UIColor blueColor];   // Demo purpose
cell.textLabel.backgroundColor = [UIColor yellowColor]; // Demo purpose
cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", (int)indexPath.row];
return cell;

但是我的单元格在左右两边都有很大的余量。知道为什么吗?

but my cell is drawn with a big margin on the left and right. Any idea why?

推荐答案

当我用iOS9测试我的应用程序时,我注意到一些UITableViews左右两边都有很大的余量。经过一番调查后,我发现了以下新方法:

When I tested my App with iOS9, I noticed huge margins, on some UITableViews, both left and right. After a bit of investigation, I found the following new method:

// iOS9
if([self.tableView respondsToSelector:@selector(setCellLayoutMarginsFollowReadableWidth:)]) {
    self.tableView.cellLayoutMarginsFollowReadableWidth = NO;
}

调用上面的代码后,在实例化UITableView之后,它应该删除它们。

When the above code is called, after instantiating your UITableView, it should remove them.

设置tableView委托后粘贴此代码。

Paste this code after you set your tableView delegate.

希望有所帮助。

这篇关于iOS 9 UITableView单元格的文本标签不是UITableView的全宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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