NSTextField에 하이퍼링크 설정
개요

구현
 HyperLinkWindowController.xib
 
HyperLinkWindowController.h
- (id)initWithMessage:(NSString *)message hyperLink:(NSString *)hyperLink;
interface에 기재한다 HyperLinkWindowController.m
init 함수
- (id)initWithMessage:(NSString *)message hyperLink:(NSString *)hyperLink {
    if (self = [super initWithWindowNibName:[self className] owner:self]) {
        _message = message;
        _hyperLink = hyperLink;
    }
    return self;
}
하이퍼링크 설정
코드 전체는 이하와 같다.
/**
 @brief ラベルを更新する
 */
- (void)updateLabels {
    // 本文の設定
    [_messageLabel setStringValue:_message];
    // ハイパーリンクの設定
    [_hyperLinkLabel setAllowsEditingTextAttributes: YES];
    [_hyperLinkLabel setSelectable: YES];
    NSMutableAttributedString *attrbutedString = [[NSMutableAttributedString alloc]
                                                  initWithString:_hyperLinkLabel.stringValue
                                                  attributes:@{
                                                               NSForegroundColorAttributeName:[NSColor blueColor],
                                                               NSFontAttributeName           :[NSFont  systemFontOfSize:13.0f],
                                                               NSUnderlineStyleAttributeName :@(NSUnderlineStyleSingle)
                                                               }
                                                  ];
    [attrbutedString addAttribute:NSLinkAttributeName
                            value:_hyperLink
                            range:NSMakeRange(0, attrbutedString.length)];
    [_hyperLinkLabel setAttributedStringValue:attrbutedString];
}
[_hyperLinkLabel setAllowsEditingTextAttributes: YES];
[_hyperLinkLabel setSelectable: YES];
AttributedString 를 설정할 수 있도록 한다 NSMutableAttributedString *attrbutedString = [[NSMutableAttributedString alloc]
                                              initWithString:_hyperLinkLabel.stringValue
                                              attributes:@{
                                                           NSForegroundColorAttributeName:[NSColor blueColor],
                                                           NSFontAttributeName           :[NSFont  systemFontOfSize:13.0f],
                                                           NSUnderlineStyleAttributeName :@(NSUnderlineStyleSingle)
                                                           }
                                           ];
AttributesString의 변수 만들기 initWithString 에 하이퍼링크 문구를 설정 attributes 에 textField UI를 하이퍼링크용으로 설정blueColor로 설정 13로 설정 [attrbutedString addAttribute:NSLinkAttributeName
                        value:_hyperLink
                        range:NSMakeRange(0, attrbutedString.length)];
[_hyperLinkLabel setAttributedStringValue:attrbutedString];
AttibutedString 변수에 NSLinkAttributeName 속성 추가 GitHub
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(NSTextField에 하이퍼링크 설정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/IKEH/items/7471b5c8a72ebe8c124f
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
Reference
이 문제에 관하여(NSTextField에 하이퍼링크 설정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/IKEH/items/7471b5c8a72ebe8c124f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)