我有一个UIView,在UIView我有UI
ImageView&我所做的是将cornerRadius设置为该UIView并设置borderWidth但是在UIView之后我得到了近1个像素空间所以我该如何解决这个问题?
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像素间距的图像.
解决方法
尝试使用它,它将在我的项目中正常工作
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;