Ios 标签的圆角不可见

Ios 标签的圆角不可见,ios,uilabel,quartz-core,Ios,Uilabel,Quartz Core,我有两个相邻的标签,它们之间有一个分隔的边框。第一个标签应仅在左上角和左下角具有圆形边框,第二个标签反之亦然。为此,我使用UIBezierPath的bezierPathWithRoundedRect绘制路径,并设置为标签层的遮罩。代码如下: _serverLabel.layer.borderWidth = 1.0; _cpuUsageLabel.layer.borderWidth = 1.0; _serverLabel.layer.backgroundColor = [UIColor grayC

我有两个相邻的标签,它们之间有一个分隔的边框。第一个标签应仅在左上角和左下角具有圆形边框,第二个标签反之亦然。为此,我使用UIBezierPath的bezierPathWithRoundedRect绘制路径,并设置为标签层的遮罩。代码如下:

_serverLabel.layer.borderWidth = 1.0;
_cpuUsageLabel.layer.borderWidth = 1.0;
_serverLabel.layer.backgroundColor = [UIColor grayColor].CGColor;
_serverLabel.layer.borderColor = [[UIColor blackColor] CGColor];
_serverLabel.backgroundColor = [UIColor clearColor];
CAShapeLayer * maskLayer = [CAShapeLayer layer];

maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: self.serverLabel.bounds byRoundingCorners: (UIRectCornerTopLeft | UIRectCornerBottomLeft) cornerRadii: CGSizeMake(10.0, 10.0)].CGPath;    
_serverLabel.layer.mask = maskLayer;

maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: self.cpuUsageLabel.bounds byRoundingCorners: UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii: (CGSize){10.0, 10.0}].CGPath;
_cpuUsageLabel.layer.mask = maskLayer;

我在自定义tableViewCell类的LayoutSubview中做了这些修改。它被正确地磨圆,但仅磨圆的边是不可见的。其他边和边中的边框可见(黑色)。提前感谢。

您可以使用Calayer和masks CAShapeLayer*maskLayer=[CAShapeLayer];maskLayer.path=maskPath.CGPath;label.layer.mask=maskLayer;其中,maskPath是使用bezierPathWithRoundedRect:byRoundingCorners:CornerRadiyYeah设置的UIBezierPath,但我这样做没有问题。我给了标签一个背景色,设置了标签的背景色并进行了检查。它将正确地变圆,但仅圆角没有边框颜色。我不明白为什么。如果我知道原因,那会很有帮助的。我再次尝试设置label.layer的边框颜色。但它仍然没有改变,绘制一个新的边框怎么样?您可以通过其基础CALayer属性设置标签的边框:#import myLabel.layer.borderColor=[UIColor greenColor].CGColor;myLabel.layer.borderWidth=3.0;我已经添加了这些行并进行了检查。它不起作用,但是。如果不设置边框宽度,边框将不可见。不。。但我正在我的项目中使用。你可以稍后再查,然后告诉我。谢谢