NSTextView에서 텍스트를 프로그래밍 방식으로 하이퍼 링크로 만드는 방법은 무엇입니까?
이렇게 :
그냥 여기를 클릭하여 등록
또는 다음과 같이 :
등록하려면 http://example.com 만
이 솔루션을 찾았 지만 macOS가 아닌 iOS에서만 작동합니다.
이 시도:
let attributedString = NSMutableAttributedString(string: "Just click here to register")
let range = NSRange(location: 5, length: 10)
let url = URL(string: "https://www.apple.com")!
attributedString.setAttributes([.link: url], range: range)
textView.textStorage?.setAttributedString(attributedString)
// Define how links should look like within the text view
textView.linkTextAttributes = [
.foregroundColor: NSColor.blue,
.underlineStyle: NSUnderlineStyle.styleSingle.rawValue
]
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다