nsview

NSView mouse events after adding subview

安稳与你 提交于 2021-02-19 02:56:06
问题 After I add a subview to NSView, my mouse events respond to the area of NSView minus the addedSubVIew. How can I avoid that? I want it to respond on all of the superview. Thanks. 回答1: You can also implement the hitTest: method in the container view. - (NSView *) hitTest: (NSPoint) aPoint { return [super hitTest:aPoint] ? self : nil; } Now only the container view can receive the mouse events. 回答2: You can override the subviews [NSView hitTest:] method and return the superview. - (NSView *)

How to change the background color of an NSPopupButton?

十年热恋 提交于 2021-02-08 15:54:46
问题 I am trying to tackle a problem which sounds pretty simple: changing the background color of an NSPopupButton. Interface Builder only allows changing the style to a pre-defined one and doesn't allow changing the background color. Also, setting up an IBOutlet didn't help since NSPopupButton doesn't have a setBackgroundColor method. I also tried subclassing NSPopupButton to override the drawRect method. Here's what I have tried: - (void)drawRect:(NSRect)dirtyRect { [[NSColor redColor] setFill];

How to change the background color of an NSPopupButton?

天大地大妈咪最大 提交于 2021-02-08 15:54:00
问题 I am trying to tackle a problem which sounds pretty simple: changing the background color of an NSPopupButton. Interface Builder only allows changing the style to a pre-defined one and doesn't allow changing the background color. Also, setting up an IBOutlet didn't help since NSPopupButton doesn't have a setBackgroundColor method. I also tried subclassing NSPopupButton to override the drawRect method. Here's what I have tried: - (void)drawRect:(NSRect)dirtyRect { [[NSColor redColor] setFill];

Show Window without activating (keep application below it active)

こ雲淡風輕ζ 提交于 2021-02-07 13:10:05
问题 I need to show a window (without title bar) above third party applications without my window taking focus. I have tried using an NSPanel and setting enabling non-activating, but that didn't help. I tried orderFront:self , but that didn't help either. I always needed to add [NSApp activateIgnoringOtherApps:YES]; because the window wouldn't show otherwise. I have here a sample project for just this functionality: http://users.telenet.be/prullen/TopW2.zip UIElement is set to true in the

Show Window without activating (keep application below it active)

妖精的绣舞 提交于 2021-02-07 13:07:13
问题 I need to show a window (without title bar) above third party applications without my window taking focus. I have tried using an NSPanel and setting enabling non-activating, but that didn't help. I tried orderFront:self , but that didn't help either. I always needed to add [NSApp activateIgnoringOtherApps:YES]; because the window wouldn't show otherwise. I have here a sample project for just this functionality: http://users.telenet.be/prullen/TopW2.zip UIElement is set to true in the

First responder on mouse down behavior NSControl and NSView

巧了我就是萌 提交于 2021-01-28 13:57:08
问题 I have a custom control. If it inherits from NSView , it automatically becomes the first responder when I click on it. If it inherits from NSControl , it does not. This difference in behavior persists, even if I override mouseDown(with:) and don't call super. Code: class MyControl: NSView { override var canBecomeKeyView: Bool { return true } override var acceptsFirstResponder: Bool { return true } override func drawFocusRingMask() { bounds.fill() } override var focusRingMaskBounds: NSRect {