swift - How to put a sentence in a every line of List in Swift?
问题描述
The UI structure of app looks like this
struct SheetView: View {
var body: some View {
List{
Rectangle()
.frame(width: 150, height: 5)
.foregroundColor(.gray)
.cornerRadius(10)
.opacity(50)
HStack{
Image("logo")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 100)
Text("How does diagnostic prediction works?")
.font(.largeTitle)
.fontWeight(.bold)
.padding(25)
}
Text("This app tries to predict medical diagnosys by given symptoms. It curently works with the given symptoms:")
// not a fancy way
Text("abdominal pain")
Text("abnormal menstruation")
Text("acidity")
Text("acute liver failure")
Text("altered sensorium")
Text("anxiety")
.multilineTextAlignment(.leading)
.lineSpacing(10)
Spacer()
}
.padding(20)
}
}
I have a big list of symptoms ( text ) and I want to put every symptom in a List. I tried to stack it something like
Text("abdominal pain")
Text("abnormal menstruation")
Text("acidity")
Text("acute liver failure")
Text("altered sensorium")
Text("anxiety")
but it's not a fancy way. What is the best practice to put a sentence in every line of List without stacking it using Text()?
解决方案
If you have the String
s in an array using ForEach
and have it return at Text
with that element seems like the easiest way.
推荐阅读
- python - pygame中的移动速度
- entity-framework - 如何防止 Entity Framework Core tools 2.1.4 修改目标项目文件?
- php - 如何每 10 次关闭一个 div?
- oracle - 多个 PLS-00103:遇到符号“IN”
- ajax - Popstate 不适用于页面过渡动画
- java - 如何在 Java Spring Web App 中获取项目路径
- laravel - 使用 orWhereHas laravel 雄辩查询检查数据是否存在于另一个表中
- shibboleth - 通过不设置特定路径,使用 Shibboleth SAML/SSO 保护 IIS 中的根目录
- sql - 左连接未优化
- javascript - 如何循环 API 调用