-2

I need to implement message View like WhatsApp - message time and ticks should be approximately on the same line with the last line of text if the text does not reach the end, and if it reaches the end, then the time is transferred to the next line.

How can this be done? Maybe there are examples or tutorials?

sample message from WhatsApp

now i get it like this:

my sample

code:

    HStack(alignment: .lastTextBaseline) {
            VStack(alignment: .leading, spacing: 8) {
                if isFirstMessage, !isCurrentUser {
                    Text(name)
                        .font(.headline)
                        .foregroundColor(Colors.message.color)
                }
                HStack(alignment: .bottom) {
                    Text(text)
                        .foregroundColor(Colors.message.color)
                    timeCheckMarkOverlay
                }
            }
        }
        .padding([.leading, .trailing], 12)
        .padding([.top, .bottom], 7)
        .cornerRadius(10)
        .background(isCurrentUser ? Colors.currentUserMessage.color : Colors.anotherUserMessage.color)
  • 1
    See this https://stackoverflow.com/questions/15113461/decrease-the-width-of-the-last-line-in-multiline-uilabel then wrap the UIKit code in a UIVIewRepresentable – NoeOnJupiter Jun 01 '22 at 09:21

0 Answers0