3

Android implements outline via outer stroke. So you can have a really thick outline that looks like this:

Android thick outline

iOS implements outline via inner stroke. So a thick outline will totally consume the inner color:

iOS thick outline

Is there any way to create an outer stroke effect on iOS?

P.Melch
  • 8,066
  • 43
  • 40
  • https://developer.apple.com/library/archive/qa/qa1531/_index.html ? Also what attributes did you set to your NSAttributedString? Which values for the stroke? – Larme Jul 10 '18 at 09:14
  • This is not about how to create a text with stroke _and_ fill. This post is about the way iOS draws a stroke. It does this by drawing the stroke on the _inside_ of the characters (ie innner stroke). This way the fill color gets consumed if I use a really thick outline. In this context the set attributes is irellevant imho cause this move the discussion away from the algorithm used by iOS to how to configure the inner stroke. but for the sake of completenes: NSStrokeWidthAttributeName: -10; NSStrokeColorAttributeName:blackColor. What I want to know if it's possible to create an *outer* stroke – P.Melch Jul 11 '18 at 08:04
  • Sorry, misread, I though that the value (positive/negative) was helping to set the stroke inner/out. and that for the out, there was an "issue" with the fill color then – Larme Jul 11 '18 at 08:22
  • @P.Melch Have you found a solution? – zeke Jun 18 '20 at 16:33
  • @P.Melch Have you found a solution? – Tyler Rutt Jul 19 '22 at 18:59
  • No. The results look vaguely similar but not the same. – P.Melch Jul 20 '22 at 21:05

1 Answers1

0

I implemented the same feature by using this lib: https://github.com/tobihagemann/THLabel

However, I have to do more. If your label displays a complex attributed string with some attributes like underline, strike through, this lib will not help you to solve completely.

I've changed a bit in draw(_:) to only manually draw a filled image based on the main text shape that seems to look like an outer stroke. https://github.com/dungntm58/THLabel/blob/swift/THLabel/THLabel.swift Unfortunately, it does not work properly in some cases. I hope it will help you to solve your issue.

Edit: I updated my code to solve a lot of issues about label shadow, I think it will work perfectly.