1

我对 UIView 上的圆角有一个奇怪的问题。正如您在屏幕截图中看到的那样,黑色角落并不完全精确,这意味着可以看到底层视图的一些像素(即角落中的白色像素用黄色箭头突出显示)。

我已经设置了这样的角半径:

contentView.layer.cornerRadius = 5.0f;
contentView.layer.masksToBounds = YES;

contentView 是一个 UIView 对象,它包含一个 UIImageView 作为子视图(当前显示 Google 图像)。此外,contentView 作为子视图添加到屏幕截图中显示的主视图中。

我已经尝试了几件事但没有令人满意的结果,包括:

  • 将圆角半径直接添加到主视图,而不是内容视图
  • 增加/减少边框大小和圆角半径的值
  • 将所有提及的视图的背景颜色更改为黑色、白色和清晰(目前是清晰的)

我感谢您的帮助。谢谢!

截图

  • 1
  • 2
4

2 回答 2

1

请在代码中尝试:

contentView.layer.borderWidth=1;
contentView.layer.borderColor=[UIColor blackColor].CGColor;
contentView.layer.cornerRadius=5;
于 2013-01-16T13:58:53.777 回答
0

我试过下面的代码对我来说很好

UIView *vi = [[[UIView alloc] initWithFrame:frame] autorelease];
vi.backgroundColor = [UIColor clearColor];
[self addSubview:vi];

UIImageView *imgv = [[[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, frame.size.height)] autorelease];
imgv.layer.cornerRadius = 4.0;
imgv.layer.borderColor = [UIColor whiteColor].CGColor;
imgv.clipsToBounds = YES;
imgv.image = [UIImage imageNamed:@"xxxxxx.png"];
[vi addSubview:imgv];

希望对你有一点帮助。

于 2013-01-16T13:44:58.263 回答