Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在SwiftUI HStack中对齐旋转的文本_Ios_Alignment_Swiftui_Text Alignment - Fatal编程技术网

Ios 在SwiftUI HStack中对齐旋转的文本

Ios 在SwiftUI HStack中对齐旋转的文本,ios,alignment,swiftui,text-alignment,Ios,Alignment,Swiftui,Text Alignment,我正在尝试尾随对齐旋转的文本(旋转后顶部对齐?)。我尝试了HStack对齐参数、每个文本的alignmentGuide()视图修饰符和一个自定义垂直对齐指南的不同组合,但未能达到预期效果。 我没有使用.frame()ViewModifier,因为文本的比例因子可能会根据文本视图的数量而改变 所需的对齐以红线显示: 基本代码: HStack { VStack { Spacer() Rectangle() .fill(Color.gr

我正在尝试尾随对齐旋转的文本(旋转后顶部对齐?)。我尝试了
HStack对齐参数
、每个文本的
alignmentGuide()视图修饰符
和一个
自定义垂直对齐指南
的不同组合,但未能达到预期效果。 我没有使用
.frame()ViewModifier
,因为文本的比例因子可能会根据文本视图的数量而改变

所需的对齐以红线显示:

基本代码:

HStack {
    VStack {
        Spacer()
        Rectangle()
            .fill(Color.green)
            .frame(height: 80)
        Text("Text 1")
            .rotationEffect(.degrees(-90))
            .padding(.top, 30)
    }
    VStack {
        Spacer()
        Rectangle()
            .fill(Color.green)
            .frame(height: 80)
        Text("Text 2")
            .rotationEffect(.degrees(-90))
            .padding(.top, 30)
    }
    VStack {
        Spacer()
        Rectangle()
            .fill(Color.green)
            .frame(height: 80)
        Text("Text 34")
            .rotationEffect(.degrees(-90))
            .padding(.top, 30)
    }
}
试试这个:

VStack(alignment: .trailing) {
            Text("Text 1")

            Text("Text 2")

            Text("Text 34")

        }.rotationEffect(.degrees(-90))

您的评论更新的新答案:

HStack {
            VStack {
                Rectangle()
                    .fill(Color.green)
                    .frame(height: 80)
                Text("Text 1")
                    .rotationEffect(.degrees(-90), anchor: .bottomTrailing)
                    .padding(.top, 30)
            }
            VStack {
                Rectangle()
                    .fill(Color.green)
                    .frame(height: 80)
                Text("Text 2")
                    .rotationEffect(.degrees(-90), anchor: .bottomTrailing)
                    .padding(.top, 30)
            }
            VStack {
                Rectangle()
                    .fill(Color.green)
                    .frame(height: 80)
                Text("Text 34")
                    .rotationEffect(.degrees(-90), anchor: .bottomTrailing)
                    .padding(.top, 30)
            }
        }
    }

好的,现在是我的最后一个,希望您满意;)


抱歉,伙计,我刚刚意识到我把我的例子简化了。我将更新我的问题。给了你一票。我的坏…它必须和矩形中心对齐(见上面更新的图片)。目标是为多个条形图创建X轴描述。条形图的数量将是动态的,因此条形图矩形的宽度可能会改变以适应更多的条形图。
struct ContentView: View {
    var body: some View {
        HStack {
            VStack(alignment: .center) {
                Rectangle()
                    .fill(Color.green)
                    .frame(height: 80)
                Text("Text 1")
                    .frame(width:100, height:100, alignment: .trailing)
                    .rotationEffect(.degrees(-90))
            }
            VStack(alignment: .center) {
                Rectangle()
                    .fill(Color.green)
                    .frame(height: 80)
                Text("Text 2")
                    .frame(width:100, height:100, alignment: .trailing)
                    .rotationEffect(.degrees(-90))
            }
            VStack(alignment: .center) {
                Rectangle()
                    .fill(Color.green)
                    .frame(height: 80)
                Text("Text 345")
                    .frame(width:100, height:100, alignment: .trailing)
                    .rotationEffect(.degrees(-90))
            }
        }
    }
}