0

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

4

0 回答 0