换行时无法对齐 Button 中的左侧文本

Can't align left text in Button when it wraps

如何让文本在 Button 中左对齐,一旦它换行到第二行,对齐就会居中。我尝试添加一个 Spacer() 但没有解决它。

Button(action: {
                name = foodcombo.pair
                foodCombos = database.retrieveFilteredCombos(main: foodcombo.pair)
                maxTastes = database.maxTastes(main: foodcombo.pair)
              }) {
                HStack {
                  Text(foodcombo.pair)
                    .frame(width: geometry.size.width * 0.30, alignment: .leading)
                    .font(.system(size: 14))
                    
                  
                  //Spacer()
                }
              }

我认为您正在寻找 .multilineTextAlignment(.leading)。如果超过 1 行,这会导致文本视图对齐修改。

    Button(action: {
        name = foodcombo.pair
        foodCombos = database.retrieveFilteredCombos(main: foodcombo.pair)
        maxTastes = database.maxTastes(main: foodcombo.pair)
    }) {
        HStack {
            Text(foodcombo.pair)
                .frame(width: geometry.size.width * 0.30, alignment: .leading)
                .font(.system(size: 14))
                // To align a Text view, use .multilineTextAlignment
                .multilineTextAlignment(.leading)
        }
    }