코코아로 클릭 가능한 텍스트 (하이퍼 링크 텍스트)를 만들어야합니다. 클릭하면 Finder에서 열리는 대신 브라우저에서 콘텐츠가 열립니다. 어떻게하면 되나요?
이것은 내가 시도하는 코드입니다.
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",@"file:///Users/abc/index.html"]];
NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString: @"Help"];
NSRange range = NSMakeRange(0, [attrString length]);
[attrString beginEditing];
[attrString addAttribute:NSLinkAttributeName value:[url absoluteString] range:range];
// make the text appear in blue
[attrString addAttribute:NSForegroundColorAttributeName value:[NSColor blueColor] range:range];
// make the text appear with an underline
[attrString addAttribute:
NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSSingleUnderlineStyle] range:range];
[attrString endEditing];
미리 감사드립니다 ....
하위 클래스 NSTextField
및 오버라이드 mouseDown
메서드를 사용할 수 있습니다 .
-(void)mouseDown:(NSEvent *)theEvent
{
[super mouseDown:theEvent];
NSLog(@"Here"); // Delegate action back to View Controller.
}
그런 다음 텍스트에서 클릭 이벤트를들을 수 있습니다. .NET Core에서 pointerHand를 얻기 위해 커서를 변경할 수도 있습니다 resetCursorRects
.
-(void)resetCursorRects
{
[self addCursorRect:[self bounds] cursor:[NSCursor pointingHandCursor]];
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다