向每个单元格添加带有cornerRadius的UILabel时,UITableView会爬行 [英] UITableView comes to a crawl when adding a UILabel with cornerRadius to each cell

查看:152
本文介绍了向每个单元格添加带有cornerRadius的UILabel时,UITableView会爬行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为表格视图中的每个单元格添加一个UILabel。这最初没有问题。当我使用 layer.cornerRadius 滚动UILabel的角落时,滚动表视图会停止。

I'm adding a UILabel to each cell in my table view. This presents no problem initially. When I round the corners of the UILabel using layer.cornerRadius scrolling the table view grinds to a halt.

 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];


推荐答案

我在自己面前试过这个,发现它是对于任何移动的视图都没用。您应该创建一个带圆角的图像,并将其添加为标签的背景。

I've tried this before myself and found that it's useless for any kind of view that moves. You should create an image with rounded corners and add that as the background of your label instead.

这篇关于向每个单元格添加带有cornerRadius的UILabel时,UITableView会爬行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆