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

android - questions about switching from C2DM to GCM -

c++ - Qt setGeometry: Unable to set geometry -

batch file - How to extract all multi-volume RAR archives from subfolders of a folder? -