6
我在使用UIBezierPath时遇到了UITableViewCell中的自动布局约束问题。我的细胞不会全宽。你可以看到图像1和图像2的不同。图像2我没有添加圆角。UITableViewCell自动布局宽度不与UIBezierPath一起使用
图像1
图像2
以前,我具有的UIView与UIBezierPath同样的问题(你可以看到所述第一2的UIView用 “0”) 。我使用的解决办法是掩盖viewDidLayoutSubviews舍入角落像下面的代码: -
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[self.view layoutIfNeeded];
UIView *container = (UIView *)[self.view viewWithTag:100101];
[container setBackgroundColor:[UIColor colorWithHexString:@"ffffff"]];
[self setMaskTo:container byRoundingCorners:UIRectCornerAllCorners];
}
但现在我的UITableViewCell很卡,因为我不能在viewDidLayoutSubviews添加四舍五入的角落。我的代码如下: -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"myData";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
MyWClass *w = [_wData objectAtIndex:indexPath.row];
UIView *container = (UIView *) [cell viewWithTag:200001];
[container setBackgroundColor:[UIColor colorWithHexString:w.bgColor]];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:container.layer.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = container.bounds;
maskLayer.path = maskPath.CGPath;
container.layer.mask = maskLayer;
[cell setBackgroundColor:[UIColor colorWithHexString:@"#efeff4"]];
cell.layer.masksToBounds = NO;
cell.layer.shadowOpacity = 1.0;
cell.layer.shadowOffset = CGSizeMake(0, 2);
cell.layer.shadowColor = [UIColor colorWithHexString:@"#e4e4e8"].CGColor;
cell.layer.shadowRadius = 0;
return cell;
}
我尝试添加[cell.contentView layoutIfNeeded];
但仍然相同。
任何帮助,将不胜感激。
'container.layer.masksToBounds = YES;'或'-clipsToBounds' – 0yeoj
@ 0yeoj试过了,仍然没有工作 – skycrew
如果您滚动你的细胞屏幕外,他们做自我修复滚动时他们回来? – stefandouganhyde