SwiftUI How to align the bottom of two text with different font size?

Viewed 506

I’m trying to align the bottom of two Text but the larger one looks like thismy widget looks like this. I don’t know why there’s still some space below this Text view. This is my code:

var body: some View {
GeometryReader{geometry in
    ZStack(alignment: .center){
        Image("background")
            .resizable()
        VStack(){
            HStack(alignment: .bottom){
                Text("3")
                    .lineLimit(1)
                    .font(.bold(.system(size: 100))())
                    .minimumScaleFactor(0.1)
                    .foregroundColor(Color.white)
                    .frame(width: nil, height: geometry.size.height/3, alignment: .bottom)
                    .lineLimit(1)
                    .shadow(radius: 2)
                Text("cups")
                    .foregroundColor(Color.white)
                    .font(.system(size: 12))
                    .shadow(radius: 2)
            }
            Text("Next cup on")
                .foregroundColor(Color.white)
                .font(.system(size: 10))
                .shadow(radius: 2)
                .opacity(0.5)
            Text("10 : 00")
                .foregroundColor(Color.white)
                .font(.system(size: 12))
                .shadow(radius: 1)
                .opacity(0.5)
        }
    }
}

}

What I want is the number 3’s bottom aligned to “cups”’s bottom. Thanks!

1 Answers

Instead of .bottom, you can use .lastTextBaseline as your HStack alignment:

HStack(alignment: .lastTextBaseline) {
    Text("Hello").font(.system(size: 40))
    Text("World").font(.system(size: 10))
}

enter image description here

Related