Reputation: 17
I am using NSAttributedString for my NSTextView for showing a hyperlink along with some other string. when my other string is long the link string gets wrapped (i.e that's the link string breaks and moves to next line). How to avoid it.
I will provide a sample code of what I have done:
let displayedStringValue ="Learn More"
let url = URL(string: displayedStringValue)
let linkRange = NSRange(location: detail.count, length: displayedStringValue.count)
let fullTextString = "This is sample String" + displayedStringValue
let attributedString = NSMutableAttributedString(string: fullTextString)
let learnMoreFontColor = NSColor.Red
let linkAttributes: [NSAttributedString.Key: Any] = [
.foregroundColor: learnMoreFontColor,
]
attributedString.addAttributes(linkAttributes, range: linkRange)
attributedString.addAttribute(.link, value: url, range: linkRange)
let font = NSFont.systemFont(ofSize: 14.0)
let contentFontColor = NSColor.Red
let range = NSRange(location: 0, length: attributedString.length)
attributedString.addAttribute(.font, value: font, range: range)
let contentRange = NSRange(location: 0, length: detail.length)
attributedString.addAttribute(.foregroundColor, value: contentFontColor, range: contentRange)
myTextField.linkTextAttributes = linkAttributes
myTextField.textStorage?.setAttributedString(attributedString)
When the contents of detailsstring is longer learn more string is clipping. How to avoid this?
Upvotes: 0
Views: 57