- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法聚焦在 NSBox 上并为该框绘制聚焦环?我想 [box drawFocusRingMask];可能是类似的事情,但什么也没有发生。我只需要当单击按钮时盒子周围有一个聚焦环。
提前致谢。
最佳答案
假设您要部署到 10.7 或更高版本,您可以创建一个自定义 View 类(可能是 NSBox 的子类)并让它重写以下方法:
- (BOOL)acceptsFirstResponder {
return YES;
}
- (void)drawFocusRingMask {
NSRectFill([self bounds]);
}
- (NSRect)focusRingMaskBounds {
return [self bounds];
}
如果子类化 NSBox,您可以根据需要使用 -borderRect
而不是 bounds
。
编辑:您也许可以使用 10.7 之前版本的对焦环绘图。你可能会这样做:
-(void)drawRect:(NSRect)rect
{
NSResponder* fr = [[self window] firstResponder];
if ([fr isKindOfClass:[NSView class]] && [(NSView*)fr isDescendantOf:self])
{
[NSGraphicsContext saveGraphicsState];
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSBezierPath bezierPathWithRect:NSInsetRect([self bounds],4,4)] fill];
[NSGraphicsContext restoreGraphicsState];
}
// ... normal drawing, possibly invoking super ...
}
View 还必须监视第一响应者中的变化,并对其自身调用 -setKeyboardFocusRingNeedsDisplayInRect:
。另外,在使用 NSFocusRingTypeExterior
设置期间,它可能需要自行调用 -setFocusRingType:
,尽管这可能是默认设置,具体取决于父类(super class)。
关于objective-c - NSBox 对焦环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10052628/
尝试使用 NSBox 获取适用于深色模式的背景颜色,其行为与 NSView 不同。 NSBox 是在 Interface Builder 中创建的,不能与自动布局一起使用。它不会调整任何 subvie
如何子类化 NSBox 来更改 Box 标题的宽度、高度、字体类型和背景颜色? 最佳答案 其中大多数看起来可以通过简单调用 NSBox 的访问器来设置,并且可以通过调用 [myBox title] 然
我在 NSBox 中放置了几个控件(按钮、文本字段...)。是否可以禁用用户无法访问控件的 NSBox(意味着无法单击按钮或在文本字段中写入)? nsview 怎么样? 最佳答案 NSBox 基本上只
如何为 NSBox 设置背景图像 a?我知道我们可以添加颜色,但是背景图像怎么样? 最佳答案 查看+NSColor colorWithPatternImage: . [myNSBox somehowS
我有 NSBox ,其中有 NSTableView 。我已禁用表中的滚动并尝试自动调整 NSBox 的大小以匹配 NSTableView 中的条目数,但不知道如何...有任何帮助吗? 最佳答案 您无法
有没有办法聚焦在 NSBox 上并为该框绘制聚焦环?我想 [box drawFocusRingMask];可能是类似的事情,但什么也没有发生。我只需要当单击按钮时盒子周围有一个聚焦环。 提前致谢。 最
请举例说明如何创建 NSBox 实例运行时并将其放置在 NSView 中? 最佳答案 NSView *superview = …; // Reference to the view that will
我创建了 NSBox 的子类来实现拖放。我有以下代码: @interface DropView : NSBox { } - (NSDragOperation)draggingEntered:(id )
所以我有这个应用程序,它使用视觉效果 View 来制作应用程序的容器,在这个应用程序中,我有一个使用 NSBox 的行分隔符,当我运行它时,它会出现这个 你可以看到它出现了,但是它周围有一个 1 或
我需要在 NSBox 中添加一些内容、图像和一些文本。为此,我使用 NSBox 类的方法并在对象上调用它们。 我创建了一个 IBOutlet: @IBOutlet 弱变量 theBox: NSBox!
如何以编程方式将 NSBox 更改为 isHidden:YES|NO? 最佳答案 NSView 的任何子类都会响应 setHidden:方法,因此只需调用即可更改它 [box setHidden:YE
我有 NSPopover 和 NSBox , subview 是:MKMapView 和 NSImageView。在黑暗模式下,整个 NSBox 向所有 subview 添加 Gamma /色调。这不
我想在 slider 移动时在 NSBox 中填充颜色。我正在使用以下代码。 -(IBAction)slider1move:(id)sender { [self.box setFillColo
我想将 NSBox 的背景设置为渐变。在 Interface Builder 中,可以将 NSBox 的背景颜色设置为 selectedMenuColor (渐变)。 NSBox 只有一个 setFi
我最近使用过 Array.forEach{ $0.isHidden = false } 使用 Swift 3 在 Xcode 8 中使用 NSTextFields for macOS 进行操作。我正在
我有一个NSBox,NSBox内部有一个NSImageView来显示占位图片。我创建了一个自定义类(NSBox 的子类),并使其接受拖动我想要的文件。但是当我拖动 NSBox 内的 NSImageVi
我有一个子类 NSBox。在里面我嵌入了一些 NSTextfields,它们在其角落显示了一些奇怪的工件(请参阅 image here )。这是我的 NSBox 子类代码: - (void)d
我正在构建一个使用 Horizontal Line 的应用程序(这只是 NSBox 的一个特例)。我已经把组件放入界面了,但是要调整线条的粗细呢。 NSBox 有一个 setBorderWidth
如何更新 NSCollectionView 以使用 NSBox 显示当前选定的项目?在列表中显示选择似乎是一件基本的事情,但我在这方面遇到了各种各样的麻烦。 我读过这篇文章question还查看了 s
我在主视图中设置了一个接受拖放的 NSBox。我们将 URL 存储到 str 中。然后我们加载图像并将其添加到 NSBox 的内容 View 中。 imageView = [[NSImageView
我是一名优秀的程序员,十分优秀!