UILabel Background Color Leaks to Border

前端 未结 6 1926
予麋鹿
予麋鹿 2021-02-19 03:48

I\'m creating a UILabel to which I set the background color and corner radius with the following code:

self.scoreLabel.backgroundColor = [UIColor DISRed];// cust         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-19 04:14

    It is probably anti aliasing issue. you can better fix it by adding a bezier path around the corners.

    CAShapeLayer *subLayer = [[CAShapeLayer alloc] init];
    [subLayer setFillColor:[UIColor clearColor].CGColor];
    [subLayer setStrokeColor:[UIColor whiteColor].CGColor];
    [subLayer setLineWidth:1.0];
    [subLayer setPath:[UIBezierPath bezierPathWithRoundedRect:imageView.bounds cornerRadius:imageView.layer.cornerRadius].CGPath];
    [imageView.layer addSublayer:subLayer];
    

提交回复
热议问题