CAShapeLayer used in UIView subclass doesn't work

China☆狼群 提交于 2019-12-03 08:15:50

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!