简体   繁体   English

如何更改仅针对iOS目标C中特定单元格的自定义表格视图单元格的框架?

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

i am using custom table view cell, if a row is odd then i have to give padding 10 left and right of a cell, otherwise no padding. 我正在使用自定义表格视图单元格,如果一行是奇数,那么我必须给单元格左右两侧填充10,否则不添加填充。 I had used setFrame in custom table view class as follows. 我在自定义表格视图类中使用了setFrame,如下所示。 But its giving padding for all cells.I want to give padding only for odd rows. 但是它给所有单元格提供了填充。我只想为奇数行提供填充。 Advance Thanks for any help. 预先感谢您的任何帮助。

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

}

Add an attribute to your custom cell, like a boolean. 将属性(如布尔值)添加到自定义单元格。 Then in setFrame : 然后在setFrame中:

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

Then 然后

- (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