0

隣接する 2 つのラベルがあり、それらの間に分離された境界線があります。1 番目のラベルは、左上隅と左下隅のみの境界線を丸くする必要があり、2 番目のラベルはその逆にする必要があります。そのために、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