我想将UITableViewCell宽度设置为280并从(20,0)
开始意味着细胞的X轴上应该有20个点的插入物。
然而,当我更改表格单元格的内容视图框架时 - 整个单元格位于一些我想要的大小的黑色正方形后面 我的新单元格看起来像this
这是我的代码: 在tableViewController的viewDidLoad中
[tableView registerNib:[UINib nibWithNibName:[self layoutName] bundle:[NSBundle mainBundle]] forCellReuseIdentifier:[self cellIdentifier]];
初始化单元格
-(void)initialize{
// [self setBackgroundColor:[UIColor clearColor]];
// [self setTintColor:[UIColor clearColor]];
self.backgroundView = [[WBChildCellBackground alloc]initWithFrame:CGRectInset([self frame], 20, 0)];
[self.backgroundView setHidden:YES];
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
self.autoresizingMask =UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
self.contentView.contentMode = UIViewContentModeRedraw;
self.autoresizesSubviews = YES;
self.contentView.autoresizesSubviews = YES;
self.contentMode = UIViewContentModeRedraw;
self.originalFrame = self.frame;
}
然后我调用此代码:
-(void)layoutSubviews{
[super layoutSubviews];
CGRect frame = self.bounds;
frame.origin.x = frame.origin.x + self.cellInset;
frame.size.width = frame.size.width - 2*self.cellInset;
if(self.cellInset == 0){
frame = self.originalFrame;
}
self.contentView.bounds = frame;
[self.contentView layoutSubviews];
}
-(void)setCellInset:(CGFloat)cellInset{
_cellInset = cellInset;
[self layoutSubviews];
}
为什么我的细胞没有按照我想要的方式改变?