在ios中的两个标签的圆角

时间:2017-02-28 07:24:56

标签: ios objective-c uilabel native rounded-corners

我提到左右两个标签。 现在我试图从左侧标签左侧和右侧标签右侧的角落

我试过这个:

cell.rightLabel.layer.cornerRadius = UIRectCornerBottomLeft |  UIRectCornerTopLeft;

(此代码也无效,所有边框都被舍入..)

cell.rightLabel.layer.cornerRadius = 8;

 cell.leftlabel.layer.cornerRadius = UIRectCornerBottomRight | UIRectCornerTopRight;
  cell.leftlabel.layer.cornerRadius = 8;

2 个答案:

答案 0 :(得分:1)

将属性clipsToBounds设置为或将MasksToBounds设置为

cell.rightLabel.clipsToBounds = YES;
cell.leftlabel.clipsToBounds = YES;

试试这个

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.rightLabel.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft ) cornerRadii:CGSizeMake(10.0, 10.0)];

        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = cell.rightLabel.bounds;
        maskLayer.path  = maskPath.CGPath;
        cell.rightLabel.layer.mask = maskLayer;

答案 1 :(得分:0)

试试这个:

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.label.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft ) cornerRadii:CGSizeMake(10.0, 10.0)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.view.bounds;
maskLayer.path  = maskPath.CGPath;
self.label.layer.mask = maskLayer;

我希望它的工作.....