Source code for the WriteFreely SwiftUI app for iOS, iPadOS, and macOS
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

42 rader
1.1 KiB

  1. import SwiftUI
  2. struct PostCell: View {
  3. var post: Post
  4. var body: some View {
  5. NavigationLink(
  6. destination: PostEditor(
  7. textString: post.editableText,
  8. postStatus: post.status
  9. )
  10. ) {
  11. HStack {
  12. VStack(alignment: .leading) {
  13. Text(post.title)
  14. .font(.headline)
  15. .lineLimit(1)
  16. Text(buildDateString(from: post.createdDate))
  17. .font(.caption)
  18. .foregroundColor(.secondary)
  19. .lineLimit(1)
  20. }
  21. Spacer()
  22. PostStatusBadge(postStatus: post.status)
  23. }
  24. }
  25. }
  26. func buildDateString(from date: Date) -> String {
  27. let dateFormatter = DateFormatter()
  28. dateFormatter.dateStyle = .long
  29. dateFormatter.timeStyle = .short
  30. return dateFormatter.string(from: date)
  31. }
  32. }
  33. struct PostCell_Previews: PreviewProvider {
  34. static var previews: some View {
  35. PostCell(post: testPost)
  36. }
  37. }