簡體   English   中英

如何更改僅針對iOS目標C中特定單元格的自定義表格視圖單元格的框架?

[英]How to change frame of a custom table view cell only for a particular cell in ios objective c?

我正在使用自定義表格視圖單元格,如果一行是奇數,那么我必須給單元格左右兩側填充10,否則不添加填充。 我在自定義表格視圖類中使用了setFrame,如下所示。 但是它給所有單元格提供了填充。我只想為奇數行提供填充。 預先感謝您的任何幫助。

- (void)setFrame:(CGRect)frame {
        frame.origin.x += 10;
        frame.size.width = frame.size.width - 20;
        [super setFrame:frame];

}

將屬性(如布爾值)添加到自定義單元格。 然后在setFrame中:

- (void)setFrame:(CGRect)frame {
    if(self.isOdd) {
        frame.origin.x += 10;
        frame.size.width = frame.size.width - 20;
    }
    [super setFrame:frame];
}

然后

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    [...]
    //check if your cell is odd or not
    if(theCellIsOdd)
        [theCell setIsOdd:YES];
    else
        [theCell setIsOdd:NO];
    [...]
    return theCell;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM