Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIView上的圆角不精确_Iphone_Ios_Objective C_Uiview - Fatal编程技术网

Iphone UIView上的圆角不精确

Iphone UIView上的圆角不精确,iphone,ios,objective-c,uiview,Iphone,Ios,Objective C,Uiview,我有一个奇怪的问题,在一个视图圆角正如您在屏幕截图中所看到的,黑角并不精确,这意味着可以看到基础视图的一些像素(即用黄色箭头突出显示的角中的白色像素) 我已将拐角半径设置为: contentView.layer.cornerRadius = 5.0f; contentView.layer.masksToBounds = YES; contentView是一个UIView对象,它包含一个UIImageView作为子视图(当前显示Google图像)。此外,contentView作为子视图添加到屏幕

我有一个奇怪的问题,在一个视图圆角正如您在屏幕截图中所看到的,黑角并不精确,这意味着可以看到基础视图的一些像素(即用黄色箭头突出显示的角中的白色像素)

我已将拐角半径设置为:

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

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

  • 将角半径直接添加到主视图,而不是内容 看法
  • 增加/减少边框大小和角半径的值
  • 将所有提到的视图的背景色更改为黑色、白色和清晰(当前为清晰)
我感谢你的帮助。谢谢

屏幕截图


我尝试了以下代码,这些代码对我来说很好

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

希望它能对您有所帮助。

我已经尝试了以下代码,对我来说效果很好

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

希望它能对您有所帮助。

请尝试以下代码:

contentView.layer.borderWidth=1;
contentView.layer.borderColor=[UIColor blackColor].CGColor;
contentView.layer.cornerRadius=5;

请在代码中尝试此操作:

contentView.layer.borderWidth=1;
contentView.layer.borderColor=[UIColor blackColor].CGColor;
contentView.layer.cornerRadius=5;

尝试contentView.clipstobunds=YES;属性clipsToBounds可以帮助您,将其设置为“是”。@CRDave:我已经尝试过了,但没有效果。据我所知,这应该具有与UIImageView和UIView的masksToBounds.bounds相同的效果?请尝试此链接Try contentView.clipsToBounds=YES;属性clipsToBounds可以帮助您,将其设置为“是”。@CRDave:我已经尝试过了,但没有效果。据我所知,这应该与UIImageView和UIView的masksToBounds.bounds具有相同的效果?请尝试此链接确定,现在它可以工作了。我所做的是:1.)将contentView的背景色设置为清晰(正如在代码中所观察到的)2.)按照@CRDave的建议,在imageview和contentView之间添加了一个小的边距(1pt),但我认为这在某种程度上是一个bug,或者是一个奇怪的行为。但它现在起作用了,我很高兴。:-)有什么区别?请添加一些解释OK,现在它可以工作了。我所做的是:1.)将contentView的背景色设置为清晰(正如在代码中所观察到的)2.)按照@CRDave的建议,在imageview和contentView之间添加了一个小的边距(1pt),但我认为这在某种程度上是一个bug,或者是一个奇怪的行为。但它现在起作用了,我很高兴。:-)有什么区别?请添加一些解释以便添加#导入。同时添加#导入。