Search code examples
swiftuiswiftui-text

How to use bold and normal text in same line in SwiftUI


I want to use multiple text formats in one Text view in SwiftUI. this would look like this:

i want to have multiple formats for text in the same text box at the same time even if it is really really really really really long text so it would need to wrap correctly. (and maybe even include links!)

I found this(How to bold text in TextField swiftUI?)  thread after a basic search, but it is not at all what I am looking for.

This would work similar to HTML's span


Solution

  • Here a simple example for you, with my example code you can code for iOS 13 or 14 as well:

    struct ContentView: View {
        
        var body: some View {
            
            Text("Hello, World!") + Text(" Hello, World!").bold() + Text(" Hello, World!").italic()
            
        }
        
    }
    

    output:

    enter image description here