2

I'm finishing up a custom UIControl. I need to show some text on the control, but I am not sure what is better praxis: add a label as a subview or draw the text inside the drawRect method. I've seen both methods, but I'm unsure what is better implementation praxis. The text doesn't need to be formated, just plain text would do fine.

Larme
  • 24,190
  • 6
  • 51
  • 81
Marcal
  • 1,371
  • 5
  • 19
  • 37

1 Answers1

3

Both methods are just fine. However you have better maintenance/control over a UILabel then your drawRect: method. You can access the label from outside sources and update it whenever you want without the need to call a updateLayout function (a trigger to call the drawRect).

So I advice you to use a label.

Totumus Maximus
  • 7,543
  • 6
  • 45
  • 69
  • it has a performance advantadge, then?. The thing is I only need to update the text from within the control, not from a view controller – Marcal Apr 10 '14 at 13:03
  • Well, the drawRect: function will redraw your entire UIControl whilst updating a label doesn't require that. However if the only time you set a text into the control (and never change it). DrawRect: might be a small performance gain. However the effort isn't worth the gain imo. – Totumus Maximus Apr 10 '14 at 13:05