سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top