CAShapeLayer used in UIView subclass doesn't work

后端 未结 1 943
[愿得一人]
[愿得一人] 2021-02-09 07:37

i tried a few hours to get a dotted border around my UIView with CAShapeLayer but i don\'t get it displayed.
ScaleOverlay.h

#import 

        
1条回答
  •  长情又很酷
    2021-02-09 07:51

    You never add shapeLayer as a sublayer of your UIView's layer, so it's never displayed onscreen. Try adding

    [self.layer addSublayer:shapeLayer_];
    

    after you set up your CAShapeLayer in your -initWithFrame: method.

    Even better, you could try making your UIView's backing layer a CAShapeLayer by overriding the following class method:

    + (Class) layerClass 
    {
        return [CAShapeLayer class];
    }
    

    You could then deal with the view's layer directly, and eliminate the additional CAShapeLayer instance variable.

    0 讨论(0)
提交回复
热议问题