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

|
var outlinedLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 50)) let strokeTextAttributes = [ NSStrokeColorAttributeName : UIColor.blackColor(), NSForegroundColorAttributeName : UIColor.lightGrayColor(), NSStrokeWidthAttributeName : -4.0, NSFontAttributeName : UIFont.boldSystemFontOfSize(52) ] outlinedLabel.attributedText = NSAttributedString(string: "Outlined", attributes: strokeTextAttributes) |
Filled ?
Note that the stroke width attribute is a negative value.
|
NSStrokeWidthAttributeName : -4.0 |
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 :

Link to the playground : MABDev.OutlinedText.playground
Documentation : https://developer.apple.com/library/mac/qa/qa1531/_index.html
Cheers,
MAB