ios - What is the best practice for creating custom UIView's? -


for creating custom views have 3 options.

  1. override

    func drawrect(_ rect: cgrect)

  2. add sub-layers view's layer.

  3. do both.

what best practice? why override drawrect if can draw in sub-layer (with easier api)?

thanks

rendering in drawrect means using cpu draw view using core graphics.

if can use composition of calayer sub-layers, better option heavy lifting done gpu.

on top of that, drawrect called on main thread, , if drawing code isn't fast app less responsive (of course can use background thread solve problem, still using cpu draw bitmap).


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -