NSAttributedString Shadow and Stroke on iOS?

Viewed 3555

When I use stroke and shadow, I get some sort of double-stroke. How can I fix this?

Playground Code:

import UIKit

var shadow = NSShadow()
shadow.shadowColor = UIColor.black
shadow.shadowOffset = CGSize(width: 0, height: 3)

class CustomLabel: UILabel {
    override func drawText(in rect: CGRect) {
        let attributes: [String: Any] = [NSStrokeWidthAttributeName: -2.0,
                          NSStrokeColorAttributeName: UIColor.black,
                          NSForegroundColorAttributeName: UIColor.white,
                          NSShadowAttributeName: shadow,
                          NSFontAttributeName: UIFont(name: "AvenirNext-Bold", size: 50)]
        self.attributedText = NSAttributedString(string: self.text ?? "", attributes: attributes)
        super.drawText(in: rect)
    }
}

let label = CustomLabel(frame: CGRect(x: 0, y: 0, width: 200, height: 100))
label.backgroundColor = UIColor.orange
label.text = "Hello"

Result:

enter image description here

1 Answers
Related