I would like to create a smart caption as SoundCloud app did. See the attachment below,
These two captions: - •PAN• - Berlin, Germany
are what I want create.
These captions seem to be executed by sizeToFit or sizeThatFits. However, if using sizeThatFits with background colour (by NSBackgroundColorAttributeName), you won't get padding both before the first and after the last letters and top and bottom paddings as well. The caption will be organised the exact fit size as these letters.
Anyway, what I would like to do is the exact same caption like the attachment picture.
Cheers,
You have two approaches here. One is to add a bit of padding after calling
sizeThatFits
. The other is to prepend and append a space to your label title.The right way about adding the padding, though, would be to extend
UILabel
and on your subclass, override the methodtextRectForBounds:limitedToNumberOfLines:
. In there, just call the same method onsuper
passing thebounds
you receive, only smaller.