Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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
Swift 如果我的lineLimit没有';在迅捷达不到2?_Swift_Text_Swiftui - Fatal编程技术网

Swift 如果我的lineLimit没有';在迅捷达不到2?

Swift 如果我的lineLimit没有';在迅捷达不到2?,swift,text,swiftui,Swift,Text,Swiftui,我创建了一个单元格,用于显示收到的消息。当一条消息很短,并且只占用一行时,它会在视图的中心对齐,但我希望它位于if的顶部 当信息太短时,如何在不更改单元格大小的情况下使用SwiftUI使文本在顶部对齐 import SwiftUI struct ConversationCell: View { var body: some View { HStack(spacing: 15) { //MARK: - Profile picture ProfilePictur

我创建了一个单元格,用于显示收到的消息。当一条消息很短,并且只占用一行时,它会在视图的中心对齐,但我希望它位于if的顶部

当信息太短时,如何在不更改单元格大小的情况下使用SwiftUI使文本在顶部对齐

import SwiftUI

struct ConversationCell: View {
  var body: some View {
    HStack(spacing: 15) {
      //MARK: - Profile picture
      ProfilePictureRounded(diameter: 44)

      VStack(alignment: .leading) {
        HStack {
          //MARK: - Sender name
          Text("Steve Jobs")
            .font(.callout)
            .fontWeight(.semibold)
            .lineLimit(1)
          Spacer()

          //MARK: - Date of message
          Text("12/12/2012")
            .font(.footnote)
            .fontWeight(.light)
            .layoutPriority(1)
            .foregroundColor(.mainGray)
        }

        //MARK: - This is where I want my text to be aligned at the top if short
        Text("The sent message can be read here")
          .font(.subheadline)
          .fontWeight(.light)
          .lineLimit(2)
          .frame(height: 40)
          .foregroundColor(.mainGray)
      }
    }
  }
}


文本
修饰符更改为以下内容:

.frame(height: 40, alignment: .top)