0

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.

Code snippet with Simulator running a Swift app

Code snippet with Simulator running a Swift app

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.