Я использую этот код. Как я могу добавить GradientColor в strokeColor? strokeColor принимает только UIColor. Могу ли я преобразовать GradientColor в UIColor?
Я хочу это сделать:
NSAttributedString.Key.strokeColor: LinearGradient(gradient: Gradient(colors: [Color.red, Color.blue]), startPoint: .leading, endPoint: .trailing)
Мой код:
struct StrokeTextLabel: UIViewRepresentable {
@Binding var fontName: String
@Binding var text: String
func makeUIView(context: Context) -> UILabel {
let attributedStringParagraphStyle = NSMutableParagraphStyle()
attributedStringParagraphStyle.alignment = NSTextAlignment.center
let attributedString = NSAttributedString(
string: text,
attributes:[
NSAttributedString.Key.paragraphStyle: attributedStringParagraphStyle,
NSAttributedString.Key.strokeWidth: 3.0,
NSAttributedString.Key.strokeColor: UIColor.red,// How can I change Gradient
NSAttributedString.Key.font: UIFont(name: fontName, size:30.0)!
]
)
let strokeLabel = UILabel(frame: CGRect.zero)
strokeLabel.attributedText = attributedString
strokeLabel.backgroundColor = UIColor.clear
strokeLabel.sizeToFit()
strokeLabel.center = CGPoint.init(x: 0.0, y: 0.0)
return strokeLabel
}
func updateUIView(_ uiView: UILabel, context: Context) { }
}