我有两个相邻的标签,它们之间有分隔的边框 . 第一个标签应仅在左上角和左下角有圆角边框,反之亦然 . 为此,我使用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类的layoutSubviews中做了这些修改 . 它是圆形的,但单独的圆形边缘是不可见的 . 其他边和边缘的边界是可见的(黑色) . 提前致谢 .