Skip to content

Add custom attribute #19

@song-react

Description

@song-react

for example

            let detailLocation = gesture.location(in: contentLabel)
            let storage = NSTextStorage(attributedString: contentLabel.attributedText)
            let manager = NSLayoutManager()
            storage.addLayoutManager(manager)
            let container = NSTextContainer(size: CGSize(width: contentLabel.bounds.size.width, height: CGFloat.greatestFiniteMagnitude))
            container.lineFragmentPadding = 0
            container.maximumNumberOfLines = contentLabel.numberOfLines
            container.lineBreakMode = contentLabel.lineBreakMode
            manager.addTextContainer(container)
            let index = manager.characterIndex(for: detailLocation, in: container, fractionOfDistanceBetweenInsertionPoints: nil)
            let attributes = attributedText.attributes(at: index, effectiveRange: nil)
            if let attrbuteValue = attributes[CustomAttributedKey] as? String {
                 print("url is ", attrbuteValue)
            }

and other type, at(@xxx) image preview etc.

custome attrbutes interface is needed

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions