Warm tip: This article is reproduced from serverfault.com, please click

SwiftUI Text

发布于 2020-11-28 18:24:22

I am reading lines from a text files and displaying those lines on a Text element.

I may have scientific notation elements in there like

10^12 
10^9

etc...

I need to display that as

10^2

10^9

and these numbers are in the middle of phrases, like..

The universe has 10^12 bla bla bla

How can I do that?

I show no code because I am clueless on that one.

Thanks

Questioner
Ronnie
Viewed
0
Omid 2020-11-29 10:03:14

This kind of things are much easier in SwiftUI, there is lots of ways for this job in SwiftUI one of them could be this down code:

enter image description here

struct ContentView: View {

@State var yourFirstText: String = "The universe has "

@State var yourLastText: String = " bla bla bla"

var body: some View {

    Text(yourFirstText) + Text("10") + Text("12").font(Font.footnote).baselineOffset(6.0) + Text(yourLastText)


    }
}