查看角半径问题

时间:2016-10-05 10:21:34

标签: ios objective-c uiview uiimageview calayer

我有一个UIViewUIView我有UIImageView&我所做的是将cornerRadius设置为UIView并设置borderWidth,但在UIView之后我得到差不多1个像素的空间,那么我该如何解决这个问题呢? / p>

view1.clipsToBounds = YES;
view1.layer.cornerRadius = 150;
view1.layer.masksToBounds = YES;
view1.layer.borderColor = [UIColor whiteColor].CGColor;
view1.layer.borderWidth = 50;
view1.layer.opaque = NO;

您可以查看下方显示1像素间距的图片。

Here is Demo Project Please Check That To - Click Here

此处我的观点如何 enter image description here

这就是我想要的 enter image description here

属性

enter image description here

2 个答案:

答案 0 :(得分:7)

尝试使用它,它将在我的项目中正常工作

self.view1.layer.cornerRadius=_slider1.value;//Value as per your requirement

CALayer *borderLayer = [CALayer layer];
CGRect borderFrame = CGRectInset(CGRectZero,-1,-1);
[borderLayer setBackgroundColor:[[UIColor clearColor] CGColor]];
[borderLayer setFrame:borderFrame];
[borderLayer setCornerRadius:_slider1.value];//Value as per your requirement
[borderLayer setBorderWidth:_slider2.value];//Value as per your requirement
[borderLayer setBorderColor:[[UIColor whiteColor] CGColor]];
[self.view1.layer addSublayer:borderLayer];

self.view1.clipsToBounds=YES;

答案 1 :(得分:0)

试试这项工作正常......我改变你的项目。把你给我的电子邮件ID发给我。

_view1.layer.cornerRadius = _view1.frame.size.height / 2;
_view1.layer.masksToBounds = YES;
_view1.layer.borderColor = [UIColor whiteColor].CGColor;
_view1.layer.borderWidth = 20;

_img.layer.cornerRadius = _img.frame.size.height / 2 ;
_img.clipsToBounds = YES;