SwiftUIX/SwiftUIX

AttributedText cannot wrap automatically when image and text are mixed

Aberta

#420 aberto em 28 de abr. de 2023

 (0 comentário) (0 reação) (1 responsável)Swift (490 forks)batch import
bughelp wanted

Métricas do repositório

Stars
 (8.002 estrelas)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

AttributedText cannot wrap automatically

AttributedText(getAttributedString(text: text)) .font(.pfRegular(size: 12)) .foregroundColor(.globeBlack) .environment(.lineLimit, 2) .environment(.lineBreakMode, .byWordWrapping) .environment(.lineSpacing, 3) .frame(width: appWidth - 80, alignment: .leading)

func getAttributedString(text: String) -> NSAttributedString { let att = NSMutableAttributedString(string: text + " ") att.setAttributes([.font: UIFont.pfRegular(size: 12)], range: NSRange(location: 0, length: text.count)) att.setAttributes([.foregroundColor: UIColor.globeBlack], range: NSRange(location: 0, length: text.count)) let tach = NSTextAttachment(image: UIImage.xin ?? UIImage()) tach.bounds = CGRectMake(0, -2, 36, 15) let imageAtt = NSAttributedString(attachment: tach) att.insert(imageAtt, at: att.length) return att }

Guia do colaborador