[英]How to add Margins on UITableView to inset content
我有一个表格视图,我想包含边距,以便表格的内容在左右两侧以及单元格之间都有一定的呼吸空间。
我设法做一个表视图,像:
我的情节提要设计如下:
我所做的是在主视图中添加了UITableView
,并留出了10个边距。我添加了如图所示的约束。 将Seperator style
更改为None
。
然后,我添加了两个UITableViewCell
。
并实现了如下方法:
// Row count (Twice as needed, for showing the insect)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 15*2;
}
// Returns cell based on indexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
// Decides whether content or inset
if (indexPath.row%2)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"ReuseInset"];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:@"ReuseMe"];
cell.textLabel.text = @"MMP";
}
return cell;
}
// Returns custom row height based on indexpath
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ if (indexPath.row%2)
{
return 10.0;
}
return 70.0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.