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

Add custom attribute #19

Open
DingSoung opened this issue Jul 18, 2019 · 1 comment
Open

Add custom attribute #19

DingSoung opened this issue Jul 18, 2019 · 1 comment

Comments

@DingSoung
Copy link

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

@chrisdhaan
Copy link
Owner

I'm not quite sure I understand what you want in a custom attributes interface. Could you give me a more detailed description of what you are showing me in that example @DingSoung

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants