How to outline your UILabel & UIButton

I recently had a problem with a yellow label on a dynamic background that can sometimes also be yellow.  The two common solutions are

  • Add a shadow.
  • Outline your text.

NSAttributedString offers everything you need to do it.

Filled & Outlined

Screen Shot 2016-06-09 at 1.32.07 PM


Filled ?

Note that the stroke width attribute is a negative value.

This is to tell the drawing engine it is a “Stroke & Fill” operation.  Otherwise it’ll just ignore the “NSForegroundColorAttributeName” and leave the text transparent like this :

Screen Shot 2016-06-09 at 1.44.33 PM

Link to the playground : MABDev.OutlinedText.playground

Documentation :



2 thoughts on “How to outline your UILabel & UIButton”

Leave a Reply to Lily Cancel reply

Your email address will not be published. Required fields are marked *