希望你们一切都好。
我的申请中有一个小问题。我有一个带有自定义单元格的表格视图。在我的自定义单元格类中,我做了一个 uiview
UIView* cellView = [[UIView alloc] initWithFrame:self.contentView.frame];
cellView.backgroundColor = [UIColor grayColor];
[self.contentView addSubview:cellView];
Problem is uiview is not fitting in my cell frame properly. Cellforrow is as :
- (SummaryViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell";
SummaryViewCell *cell = (SummaryViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
cell = [[SummaryViewCell alloc] init];
}
cell.backgroundColor = [UIColor blueColor];
return cell;
}
我尝试过 initWithFrame:self.contentView.frame] 但发生了同样的问题(uiview 出现在单元格中但只覆盖了单元格的一半),我也尝试过 cellView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self. frame.size.width 与高度相同)但失败了。需要您宝贵的建议和想法。非常感谢。
你在哪里创建子视图?
尝试在 -layoutSubviews 方法中执行此操作。
- (void)layoutSubviews {
[super layoutSubviews];
UIView* cellView = [[UIView alloc] initWithFrame:self.contentView.frame];
cellView.backgroundColor = [UIColor grayColor];
[self.contentView addSubview:cellView];
}
子视图的所有框架都已在此方法内计算,您应该收到子视图的正确宽度\高度。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)