Ios 使用QuartzCore在UIView周围绘制边框会导致边框比视图小1像素;
我试图用下面的代码绘制一个自定义视图,但由于某些原因,边框在顶部的间隙很小,渲染不正确Ios 使用QuartzCore在UIView周围绘制边框会导致边框比视图小1像素;,ios,objective-c,uiview,quartz-core,Ios,Objective C,Uiview,Quartz Core,我试图用下面的代码绘制一个自定义视图,但由于某些原因,边框在顶部的间隙很小,渲染不正确 self.infoContainerView = [[UIView alloc] initWithFrame:CGRectMake(12, (self.contentImage.image.size.height/self.contentImage.image.size.width)*320.0-50), self.view.frame.size.width - 24, self.view.frame
self.infoContainerView = [[UIView alloc] initWithFrame:CGRectMake(12, (self.contentImage.image.size.height/self.contentImage.image.size.width)*320.0-50), self.view.frame.size.width - 24, self.view.frame.size.height - self.contentImage.frame.size.height - 24)];
self.infoContainerView.backgroundColor = [UIColor whiteColor];
self.infoContainerView.layer.borderWidth = 0.5f;
self.infoContainerView.layer.borderColor = [[[UIColor blackColor] colorWithAlphaComponent:0.15f] CGColor];
这就是结果:
尝试给边框颜色,如
self.infoContainerView.layer.borderColor = [[UIColor blackColor] CGColor];
尝试将borderWidth更改为1.0fI也尝试过,无论宽度是多少,例如5.0f,它仍然存在:/In the image border color not black color[[UIColor blackColor]CGColor]这将解决此问题。infoContainerView=[[UIView alloc]initWithFrame:cRectMake(12,10,self.view.frame.size.width-24,self.view.frame.size.height-self.contentImage.frame.size.height-24);如果您有白色背景视图,您可以得到问题。我实际发现了问题所在。代码中的y坐标由(self.contentImage.image.size.height/self.contentImage.image.size.width)*320-50给出。当我在上面使用ceilf()时,问题自行解决了。