Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributedText cannot wrap automatically when image and text are mixed #420

Open
JPSaber opened this issue Apr 28, 2023 · 0 comments
Open
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@JPSaber
Copy link

JPSaber commented Apr 28, 2023

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
}

@vmanot vmanot added help wanted Extra attention is needed bug Something isn't working labels Apr 28, 2023
@vmanot vmanot self-assigned this Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants