现在,如果我设置了具有所需宽度和高度的框架,我可以从我的“文章”中看到我想要的文本。
如果高度足够长,它将显示所有文章“正文”,但空间很大。我希望框架可以根据我拥有的文本大小调整它的大小,以便滚动视图可以根据每个文章正文所需的文本框架正确滚动。
import SwiftUI
let articles = [
Article (id: 0, title: "Trump as President", body: "Some very short string for the article at the moment."),
Article (id: 1, title: "Obama as President", body: "He may not have been the worst but was he every really the best? Could he have done more or less from what we know?"),
Article (id: 2, title: "Tanner Fry as President", body: "Who knows how well that would work as if Tanner Fry was the president. However we do know a little bit about him from his experience as a programmer. I mean who can just pick up different langauges just off the bat and start creating code for apps to run on their watch and/or phone? Not too many people know how to do that but you know who does? Tanner Fry does, that's right.")
]
var height = 0
struct ContentView: View {
var body: some View {
// Watch res = 448 - 368
ScrollView(.vertical) {
VStack(spacing: 10){
Text("Your News").font(.title)
ForEach(0..<articles.count) {index in
Text(articles[index].title)
Text(articles[index].body).frame(width: 170, height: 170)
// Text(articles[index].body).lineLimit(50).padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
// Height needs to be variable based on the amount of text in the
// articles description. OR find a wrapper
// We're talking about the frame for the body of text
}
}
}
}
}
如果我的高度足够长,frame
我可以滚动我的所有内容。article.body
否则它会截断文本。有什么方法可以使文本长度的高度更加可变,以便 watchOS 在通过滚动时正常工作ScrollView
?我错过了什么吗?
感谢您的宝贵时间,非常感谢。