【发布时间】:2016-08-25 03:11:22
【问题描述】:
我想创建一个表格视图,它有一些圆形子视图作为 UIView。我设置了 UIView 的 layer.cornerRadius 和 clipsToBounds。但有些观点并不圆。谁能帮我解决这个问题或给我一些建议?
我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString * settCellID = @"settingCellID";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:settCellID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:settCellID];
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(100, 10, 20, 20)];
view.layer.cornerRadius = 10;
view.clipsToBounds = 1;
view.layer.rasterizationScale = [UIScreen mainScreen].scale;
view.layer.shouldRasterize = 1;
view.backgroundColor = [UIColor blueColor];
[cell.contentView addSubview:view];
}
return cell;
}
结果:
【问题讨论】:
-
这是发生在设备上还是模拟器上?
-
作为行高返回的值是多少。比这个圆形视图的高度大吗?
-
这是在模拟器中发生的吗?那么有可能是模拟器故障。将模拟器比例设置为 100%(在菜单中:Window -> Scale -> 100%)然后检查。
-
这发生在模拟器和设备上。我的iphone6s也有这个问题。 @beyowulf
-
是的,行高是 43.0f @ Anuradh S
标签: ios objective-c uitableview uiview layer