简体   繁体   中英

How to make exponents in the SwiftUI

I found the new method in SwiftUI to allow you to create an exponent.

Here what I write code is based in SwiftUI on the Swift Playground.

import SwiftUI
import PlaygroundSupport

struct V: View {

    var body: some View { 

        HStack {

            Text("8")
            Text("2\n").font(Font.system(size: 10))

            }

        } 


}

PlaygroundPage.current.setLiveView(V())

The \\n allows you to break the line and make a new line in UIKit. However, SwiftUI gives you to make a top while break line and make a new line inside the second Text. You can make a size for the Font in the Text.

在此处输入图片说明

That's it! You made the exponent in SwiftUI!

The following seems look more naturally... as variant

在此处输入图片说明

var body: some View {
    Text("8") + Text("2").font(.system(.footnote)).baselineOffset(10)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM