作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法用Mac的默认突出显示颜色“突出显示”NSImageView?我只是在寻找一种方法来为我的 nsimageview 着色,以便用户可以轻松识别该对象。
谢谢
凯文
最佳答案
如果 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 来跟踪该状态。然后,每当发生任何会改变突出显示状态的事情时,您都可以将 View 设置为需要重新显示。例如,您可以在 set/get 方法中执行此操作:
- (void)setHighlighted:(BOOL)aHighlighted {
isHighlighted = aHighlighted;
[self setNeedsDisplay:YES];
}
然后,更新您的drawRect:方法以考虑isHighlighted标志。如何实现不突出显示的外观可能取决于 ImageView 的风格。您可以尝试仅调用 super 来进行绘图,但如果在测试中,您看到 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];
}
}
关于objective-c - 突出显示 NSImageView - Objective-c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4309005/
有没有一种方法可以“标记”对象的属性,使它们在反射中“突出”? 例如: class A { int aa, b; string s1, s2; public int AA
我是一名优秀的程序员,十分优秀!