tobihagemann / THLabel

UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient.
https://tobiha.de
Other
665 stars 111 forks source link

Solid stroke with outside positioning #50

Open endanke opened 4 years ago

endanke commented 4 years ago

Hi!

I'm trying to use THLabel to create a solid white background around my label that follows the shape of the text. It looks fine mostly, but some letters can cause holes in the stroke's shape, which makes it a bit ugly.

The following image shows the problem with the letter 'i': IMG_EC9B0D7411C0-1

And the desired output would be: IMG_2EB23E5F7DC1-1

I've come up with a temporary solution, but it's probably not the most optimal. In the strokeImageWithRect function I've applied a 1px white shadow on the clipping mask, then used this idea to "remove" the opacity of the blurred shadow edges: https://stackoverflow.com/questions/14622202/can-cgcontextcliptomask-mask-all-non-transparent-pixels-with-alpha-1

I wonder if there's any better way of filling the holes directly on the clipping mask's path, without using a shadow.