Question

Is it possible to set exclusion paths on a UILabel? The apple documentation states that UILabel is now built upon TextKit but a UILabel does not seem to expose a textContainer property.

I am looking to implement a tableview cell which includes multiple labels and a roux badge which the labels should not overlap (shown below).

enter image description here

If it is not possible with a UILabel how can I make a TextView act like a UILabel (no scroll, selection etc) and size it to fit it's contents?

Was it helpful?

Solution

It is correct that UILabel does not expose the TextKit stack, so you can't set an exclusion path.

However, you don't really need UILabel; it is easy to draw directly with TextKit into a rectangular graphics context, and now you can set an exclusion path (because you are drawing with TextKit). To draw with TextKit, just build the text kit "stack", customizing in any way you like, and then, when it's time to draw, call the layout manager's drawBackgroundForGlyphRange:... and drawGlyphsForGlyphRange:....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top