I need to implement view with two texts, and first text alignment need to be trailing, and second text alignment leading, but I have this.. please help me to build correct layout. i tried to put another VStack inside the HStack and assign the trailing orientation to the first and the leading to the second
this is my code example:
var body: some View {
VStack {
HStack(spacing: 10) {
Text("test1")
.font(.system(size: 12))
.fontWeight(.bold)
// .padding(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 10))
Text("testtest1")
.padding()
.font(.system(size: 14))
.foregroundColor(.black)
.multilineTextAlignment(.center)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(Color.red, lineWidth: 1)
)
Spacer()
}
.frame(width: UIScreen.screenWidth)
.padding(EdgeInsets(top: 0, leading: 40, bottom: 12, trailing: 0))
HStack(spacing: 10) {
Text("test23")
.font(.system(size: 12))
.fontWeight(.bold)
// .padding(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 10))
Text(String("testtest12"))
.padding()
.font(.system(size: 14))
.foregroundColor(.black)
.multilineTextAlignment(.center)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(Color.red, lineWidth: 1)
)
Spacer()
}
.frame(width: UIScreen.screenWidth)
.padding(EdgeInsets(top: 0, leading: 40, bottom: 12, trailing: 0))
HStack(spacing: 10) {
Text("test345")
.font(.system(size: 12))
.fontWeight(.bold)
.frame(alignment: .trailing)
// .padding(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 10))
Text("testtest1234")
.padding()
.font(.system(size: 14))
.foregroundColor(.black)
.multilineTextAlignment(.center)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(Color.red, lineWidth: 1)
)
Spacer()
}
.frame(width: UIScreen.screenWidth)
.padding(EdgeInsets(top: 0, leading: 40, bottom: 12, trailing: 0))
HStack {
Text("test6789")
.font(.system(size: 12))
.fontWeight(.bold)
// .padding(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 10))
Text("testtest123456")
.padding()
.font(.system(size: 14))
.foregroundColor(.black)
.multilineTextAlignment(.center)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(Color.red, lineWidth: 1)
)
Spacer()
}
.frame(width: UIScreen.screenWidth)
.padding(EdgeInsets(top: 0, leading: 40, bottom: 12, trailing: 0))
HStack {
Text("test01234")
.font(.system(size: 12))
.fontWeight(.bold)
// .padding(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 10))
Text("testtest56")
.padding()
.font(.system(size: 14))
.foregroundColor(.black)
.multilineTextAlignment(.center)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(Color.red, lineWidth: 1)
)
Spacer()
}
.frame(width: UIScreen.screenWidth)
.padding(EdgeInsets(top: 0, leading: 40, bottom: 12, trailing: 0))
HStack {
Text("test5")
.font(.system(size: 12))
.fontWeight(.bold)
// .padding(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 10))
Text("testtes78")
.padding()
.font(.system(size: 14))
.foregroundColor(.black)
.multilineTextAlignment(.center)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(Color.red, lineWidth: 1)
)
Spacer()
}
.frame(width: UIScreen.screenWidth)
.padding(EdgeInsets(top: 0, leading: 40, bottom: 12, trailing: 0))
}
}
But I want to make something like this:


