I have created a var
with default text attributes for an NSMutableAttributedString
:
static var textFieldDefaultTextAttributes: [NSAttributedString.Key: Any] = [
.font: UIFont(name: "Impact", size: 32)!,
.tracking: 2,
.paragraphStyle: getParagraphStyle(),
.strokeColor: UIColor.black,
.strokeWidth: 3,
.foregroundColor: UIColor.white
]
When assigning those default styles, the correct color and width are shown for the stroke but no foreground color is applied (as shown in the first image below).
However, if I comment out the line that sets the .strokeWidth
key, the corresponding white foreground color does get rendered but no stroke is shown (as seen in the second image below).
I'm relatively new to iOS development so I'm having a hard time tracking down the source of the problem.
According to the Apple Documentation,
Specify positive values to change the stroke width alone. Specify negative values to stroke and fill the text.
Just use a negative number for .strokeWidth
, so both the foreground color and the stroke are rendered.