I am trying to add first line indentation to a substring within AttributedString using paragraphStyle. But there is no effect. However it is working fine with iOS14 and older with NSAttributedString.
I am facing same problem with attaching image using NSTextAttachment in iOS15.
Other attributes such as, font, foregroundColor, underline, link etc are working perfectly.
@available(iOS 15, *)
struct ContentView: View {
var body: some View {
Text(attributedText)
}
var attributedText: AttributedString {
var attributedText = AttributedString("HELLO!!! Loren ipsum dolor test test test blah bhal blah HELLO!!! Loren ipsum dolor test test test blah bhal blah HELLO!!! Loren ipsum dolor test test test blah bhal blah HELLO!!! Loren ipsum dolor test test test blah bhal blah")
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = .byTruncatingTail
paragraphStyle.firstLineHeadIndent = 50
paragraphStyle.lineSpacing = 0
attributedText.paragraphStyle = paragraphStyle
attributedText.foregroundColor = .red
return attributedText
}
}
Code for NSTextAttachment:
let attachment = NSTextAttachment()
attachment.image = UIImage(systemName: "star")
attachment.bounds = CGRect(origin: .zero, size: CGSize(width: 30, height: 30))
attributedText.attachment = attachment