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

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

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -