Is it possible to get a listing of attributes and ranges for an NSMutableAttributedString?

前端 未结 7 1317
小蘑菇
小蘑菇 2021-02-01 12:36

I\'ve created a method that takes a NSAttributedString and I\'m looking to dynamically create a subview and label to put the string into. Because attributes like font and size n

7条回答
  •  生来不讨喜
    2021-02-01 12:59

    Swift 4:

    If you want to get the attributes for NSTextAttachment (just change the attribute value if you want font)

    commentTextView.attributedText.enumerateAttribute(NSAttachmentAttributeName,
                            in:NSMakeRange(0, commentTextView.attributedText.length),
                            options:.longestEffectiveRangeNotRequired) {
                            value, range, stop in
                                if let attachment = value as? NSTextAttachment {
                                    print("GOT AN ATTACHMENT! for comment at \(indexPath.row)")
                                }
    }
    

提交回复
热议问题