How to use AttributedString in SwiftUI. There is no API available to use AttributedString in Text
A value type for a string with associated attributes for portions of its text.
let label = UILabel() label. attributedText = NSMutableAttributedString() . bold("Address: ") .
Text
now supports markdown and also you can create custom attributes:
You can even get defined attributes remotely like:
You can combine multiple Text
objects together with a simple +
operator and that will handle some of the attributions:
Each one can have multiple and specific modifiers
Since it doesn't support directly on Text
(till iOS 15), you can bring the UILabel
there and modify it in anyway you like:
struct UIKLabel: UIViewRepresentable { typealias TheUIView = UILabel fileprivate var configuration = { (view: TheUIView) in } func makeUIView(context: UIViewRepresentableContext<Self>) -> TheUIView { TheUIView() } func updateUIView(_ uiView: TheUIView, context: UIViewRepresentableContext<Self>) { configuration(uiView) } }
var body: some View { UIKLabel { $0.attributedText = NSAttributedString(string: "HelloWorld") } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With