yes*_*bot 8 cornerradius uitableview uilabel ios
我正在为表视图中的每个单元格添加一个UILabel.这最初没有问题.当我使用layer.cornerRadius滚动来围绕UILabel的角落时,表格视图停止.
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(cell.bounds.origin.x+10 ,5, 30, 30)];
label1.backgroundColor = ([[managedObject valueForKey:@"color"] hasPrefix:@"FFFFFF"]) ? [UIColor blackColor] : color;
label1.layer.cornerRadius = 10.0f;
[cell addSubview:label1];
Run Code Online (Sandbox Code Playgroud)
Chr*_*phK 15
不需要带有角落的图像 - 请参阅fknrdcls对此问题的回答:
基本上,您只需要为标签指定透明背景,然后将背景颜色添加到图层中.然后,您可以禁用maskToBounds,这可以大大提高性能.所以你的代码变成:
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(cell.bounds.origin.x+10 ,5, 30, 30)];
label1.backgroundColor = [UIColor clearColor];
label1.layer.backgroundColor=[UIColor whiteColor].CGColor;
label1.layer.cornerRadius = 10.0f;
label1.layer.masksToBounds = NO;
label1.layer.shouldRasterize = YES;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4781 次 |
| 最近记录: |