How to make exponents in the SwiftUI

浪尽此生 提交于 2021-01-05 13:01:25

问题


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!


回答1:


The following seems look more naturally... as variant

enter image description here

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


来源:https://stackoverflow.com/questions/60232669/how-to-make-exponents-in-the-swiftui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!