How do you override UIView's +(id)layer; class method?

半城伤御伤魂 提交于 2019-12-03 09:03:16

If you just want to set properties like backgroundColor, opacity, etc. on the default CALayer that's assigned to the UIView, you can set those on the UIView's layer at any time using something like the following:

view.layer.opacity = 0.0f;

The only time that you would need to override the - (CALayer)layer method would be if you wanted to return a custom CALayer subclass. I believe that on the iPhone Apple recommends you override the class method layerClass instead. This will return the CALayer subclass to be created when initializing your custom view. For example,

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

causes your UIView subclass to use an OpenGL layer for its backing.

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