ios - Overriding default layer type in UIView in swift -


i want subclass uiview in swift, , use cashapelayer layer type subclass - overriding layer type layerclass().

how access properties in cashapelayer, not in calayer - such path in example below. code below not compile because path not member of calayer.

override class func layerclass() -> anyclass {     return cashapelayer.self }  override func awakefromnib() {      var path: uibezierpath = uibezierpath.init(ovalinrect: cgrectmake(0, 0, 30, 10))      self.layer.path = path.cgpath } 

note self.layer returns generic calayer inside uiview, have typecast specific class make sure has correct type. can following make sure call path cashapelayer not calayer class type.

   override class func layerclass() -> anyclass {         return cashapelayer.self     }      override func awakefromnib() {         guard let shapelayer = self.layer as? cashapelayer else { return }           let path: uibezierpath = uibezierpath.init(ovalinrect: cgrectmake(0, 0, 30, 10))         shapelayer.path = path.cgpath     } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -