Ala*_*lan 14 objective-c uitableview ios
自更新到iOS 9以来,iPad横向中的表格视图单元格不再在单元测试中拉伸表格的整个宽度.
我的测试是一个简单的表,最后拍摄快照.
- (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]);
}
Run Code Online (Sandbox Code Playgroud)
对于这个例子,单元格非常简单
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;
Run Code Online (Sandbox Code Playgroud)
但是我的细胞在左右两侧画得很大.知道为什么吗?
Car*_*ine 37
当我用iOS9测试我的应用程序时,我注意到一些UITableViews左右两边都有很大的余量.经过一番调查,我发现了以下新方法:
// iOS9
if([self.tableView respondsToSelector:@selector(setCellLayoutMarginsFollowReadableWidth:)]) {
self.tableView.cellLayoutMarginsFollowReadableWidth = NO;
}
Run Code Online (Sandbox Code Playgroud)
调用上面的代码后,在实例化UITableView后,它应该删除它们.
设置tableView委托后粘贴此代码.
希望能帮助到你.
归档时间: |
|
查看次数: |
3533 次 |
最近记录: |