我已经为此工作了大约2天,所以我想我和你分享我的经验.
问题是:是否可以使分组的UITableView中的单元格宽度更小?
答案是不.
但是有两种方法可以解决这个问题.
解决方案#1:更薄的表 可以更改tableView的框架,以便表格更小.这将导致UITableView以减小的宽度渲染内部单元格.
对此的解决方案可能如下所示:
-(void)viewWillAppear:(BOOL)animated
{
CGFloat tableBorderLeft = 20;
CGFloat tableBorderRight = 20;
CGRect tableRect = self.view.frame;
tableRect.origin.x += tableBorderLeft; // make the table begin a few pixels right from its origin
tableRect.size.width -= tableBorderLeft + tableBorderRight; // reduce the width of the table
tableView.frame = tableRect;
}
Run Code Online (Sandbox Code Playgroud)
解决方案#2:让图像呈现细胞
此解决方案在此处描述:http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
我希望这些信息对您有所帮助.我花了大约2天时间尝试了很多可能性.这就是剩下的.

我想为图表显示的表格视图单元格添加水平填充.
我创建了一个子类UITableViewCell,其宽度为314像素(屏幕宽度为320),并在initWithCoder方法中设置其框架:
[self customizeXPosition:self.profileImage];
[self customizeXPosition:self.birthdayLabel];
[self customizeXPosition:self.heightLabel];
[self customizeXPosition:self.weightLabel];
Run Code Online (Sandbox Code Playgroud)
这是我的- (void)customizeXPosition:(UIView *)view:
- (void)customizeXPosition:(UIView *)view {
CGRect tmpRect = view.frame;
tmpRect.origin.x += 3.0;
view.frame = tmpRect;
}
Run Code Online (Sandbox Code Playgroud)
自定义单元格小于屏幕,我将单元格中的每个元素向右移动3个像素.我认为这段代码应该达到我的目标,但事实并非如此.视图在模拟器中没有改变,就像我没有写任何代码一样.
我怎样才能实现目标?