For iOS (I'll let someone more knowledgeable in Android development answer the second part), you'll want to use a variant of sizeWithFont:
. Depending on whether or not you wish to allow multiple lines you should check out the various methods explained in the documentation I linked.
The one I typically find most useful is sizeWithFont:constainedToSize:
where I set the constrained size to have the limited width that I have available in a view, and the height to CGFLOAT_MAX
, which allows the label to use up as much vertical space as needed (since I often have labels within vertically scrolling views).