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];
}