UITableView修改Cell的宽度问题

来源:互联网 发布:文华模拟交易软件 编辑:程序博客网 时间:2024/05/21 19:46

UITableViewCell的宽度会在添加到TableView的时候被重设,所以在 (UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:

(NSIndexPath *)indexPath 里面设置cell的宽度是没用的。

因为想给cell加一层border,所以想让cell有点缩进,google了一下,发现了一种比较方便的方法可以设置UITableViewCell的宽度。

新建一个UITableViewCell的子类,然后重写它的-setFrame:方法即可。以下为我的代码

- (void)setFrame:(CGRect)frame {

    frame.origin.x += 缩进跨度;

    frame.size.width -= 2 * 缩进跨度;

    [super setFrame:frame];

}

0 0
原创粉丝点击