UITableView修改Cell的寬度問題

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

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章