1
有沒有辦法用mac的默認高亮顏色「突出顯示」一個NSImageView?我只是在尋找一種方法來爲我的nsimageview着色,以便用戶可以輕鬆識別對象。高亮NSImageView - Objective-c
感謝,
凱文
有沒有辦法用mac的默認高亮顏色「突出顯示」一個NSImageView?我只是在尋找一種方法來爲我的nsimageview着色,以便用戶可以輕鬆識別對象。高亮NSImageView - Objective-c
感謝,
凱文
如果NSImageView的內置選項之一是不夠的,你可以繼承NSImageView,並在drawRect中,這樣做:
- (void)drawRect:(NSRect)frame {
[super drawRect:frame]; // this takes care of image
[NSBezierPath setDefaultLineWidth:4.0];
[[NSColor highlightColor] set];
[NSBezierPath strokeRect:frame]; // will give a 2 pixel wide border
}
啊,將它作爲一個變量狀態,我可能會定義一個實例變量,例如isHighlighted以跟蹤該狀態。然後,無論什麼時候會改變突出顯示的狀態,您都會將視圖設置爲需要重新顯示。你可以這樣做在設置/獲得實例方法:
- (void)setHighlighted:(BOOL)aHighlighted {
isHighlighted = aHighlighted;
[self setNeedsDisplay:YES];
}
然後更新您的drawRect:方法考慮到了isHighlighted標誌。您如何實現不突出的外觀可能取決於圖像視圖的風格。你可以嘗試調用super來完成繪圖,但是如果在測試中,你會看到超級繪圖沒有覆蓋的任何殘留或雜散的高亮像素信息,你可能需要先繪製清晰的顏色,然後調用super。
所以,這樣的事情:
- (void)drawRect:(NSRect)frame {
isHighlighted ? [[NSColor highlightColor] set] : [[NSColor clearColor] set];
[NSBezierPath setDefaultLineWidth:4.0];
if (isHighlighted) {
[super drawRect:frame];
[NSBezierPath strokeRect:frame]; // will give a 2 pixel wide border
} else {
[NSBezierPath fillRect:frame];
[super drawRect:frame];
}
}
我如何取消亮點呢? – lab12 2010-11-30 00:53:23