所以这个问题实际上涉及2个问题.
其次,如何将点击附加到NSTextField标签?我不想使用按钮,因为当我点击它时我不希望背景颜色可见,即使我隐藏了边框,点击时仍然可以看到背景颜色.我环顾四周(stackoverflow.com和谷歌)似乎没有人回答这些问题.你可能需要我如何绘制NSTextField标签的代码,所以你去.
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"Helvetica" size:14], NSFontAttributeName,[NSColor lightGrayColor], NSForegroundColorAttributeName, nil];
NSAttributedString * trashText=[[NSAttributedString alloc] initWithString: @"Trash" attributes: attributes];
[trashText drawAtPoint:NSMakePoint(20, 500)];
Run Code Online (Sandbox Code Playgroud)UPDATE
添加了更多objective-c.
MainWindowController.h
#import <Cocoa/Cocoa.h>
@interface MainWindowController : NSWindowController {
@private
}
@end
@interface EmailContents : NSView {
@private
}
@end
@interface SideBar : NSView {
@private
}
@end
@interface ClickableTextField : NSTextField
@end
Run Code Online (Sandbox Code Playgroud)
MainWindowController.m
#import "MainWindowController.h"
#import "NSAttributedString+Hyperlink.h"
int currentView = 1;
@implementation NSAttributedString (Hyperlink)
+(id)fakeHyperlinkFromString:(NSString*)inString withColor:(NSColor*)color {
NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString: …Run Code Online (Sandbox Code Playgroud)