如何调整UITableViewCell的宽度

来源:互联网 发布:软件专业介绍 编辑:程序博客网 时间:2024/04/17 01:50

UITableViewCell的宽度会在添加到TableView的时候被重设,所以在 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 里面设置cell的宽度是没用的。因为想给cell加一层border,所以想让cell有点缩进,google了一下,发现了一种比较方便的方法可以设置UITableViewCell的宽度。新建一个UITableViewCell的子类,然后重写它的-setFrame:方法即可。以下为我的代码。

- (void)setFrame:(CGRect)frame {

    frame.origin.x +=LocationCellSpace;

    frame.size.width -=2 * LocationCellSpace;

    [super setFrame:frame];

}