如何在自定义视图中创建超链接?

时间:2012-09-23 17:33:28

标签: cocoa nsview

如何在自定义视图中创建超链接.. 我创建了nsview,它包含三个超链接,但在我的情况下,它将调用方法而不是任何weblink

1 个答案:

答案 0 :(得分:0)

NSTextField子类。

通过将其backgroundColor属性设置为NSColor.clearColor来使其背景透视。

使用跟踪区域监控鼠标何时位于其上方,以便您可以更改其颜色:

NSTrackingArea* pTrackingArea= [[NSTrackingArea alloc] initWithRect:self.bounds options:NSTrackingActiveAlways | NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited owner:self userInfo:nil];
[self addTrackingArea:pTrackingArea];

跟踪区域为您调用某些鼠标操作方法。在这种情况下:

-(void)mouseEntered:(NSEvent *)theEvent
-(void)mouseExited:(NSEvent *)theEvent

在这些中设置NSTextField子类的textColor属性。

要确定用户点击的时间,请使用:

-(void)mouseUp:(NSEvent *)theEvent

并从中调用您想要的任何方法。