I have a question regarding rounded corners and text background color for a custom UIView.

Basically, I need to achieve an effect like this (image attached - notice the rounded corners on one side) in a custom UIView: Background highlight

I'm thinking the approach to use is:

  • Use Core Text to get glyph runs.
  • Check highlight range.
  • If the current run is within the highlight range, draw a background rectangle with rounded corners and desired fill color before drawing the glyph run.
  • Draw the glyph run.

However, I'm not sure whether this is the only solution (or for that matter, whether this is the most efficient solution).

Using a UIWebView is not an option, so I have to do it in a custom UIView.

My question being, is this the best approach to use, and am I on the right track? Or am I missing out something important or going about it the wrong way?

Edit
Report