nsbutton

NSButton gets drawn inside custom NSCell, but is not actually clickable

时间秒杀一切 提交于 2019-12-08 05:37:41
I have a NSTableView which contains my custom NSCell subclass, IconCell. The IconCell contains three elements : an image, text, and a button. Here's a simplified version of my drawing code ( closeButton is the button): - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { NSPoint cellPoint = cellFrame.origin; [controlView lockFocus]; CGFloat buttonWidth = [closeButton frame].size.width; [someNSImage drawInRect:NSMakeRect(cellPoint.x, cellPoint.y, ICON_WIDTH, ICON_HEIGHT) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil];

Can't Change NSButton Font

元气小坏坏 提交于 2019-12-08 04:28:25
问题 I'm trying to change the font of a NSButton subclass I've created. I'm able to set the font up when I set up the the actual button using the following code: [button setFont:[NSFont fontWithName:@"Courier" size:15]]; However, when I'm trying to do it later on in my application, it doesn't work. I'm trying to get the user to select a new font; once they've done this, I want to update this button to use the selected font. I know my font-selection process isn't the issue, as I can change the font

NSButton image shadow on mouseEntered event

自闭症网瘾萝莉.ら 提交于 2019-12-07 20:16:54
问题 I have a borderless NSButton that contains an image and is subclassed with my ButtonEffect class to detect mouseEntered and mouseExited events. My goal is to have just the edge of the image glow as the mouse enters the button area. I know I can achieve this by using two different images (one with shadow and another without) but I need to do this with one image. Here's an example of what I hope to achieve for the mouseEntered event: And here's what it should look after the cursor leaves the

mouseEntered event disabled when mouseDown (NSEvents Mac)

做~自己de王妃 提交于 2019-12-07 13:40:13
问题 I have created an NSButton class, and when rolling over my buttons it happily detects mouseEntered and mouseExited events. But as soon as the mouseDown event occurs, so long as the mouse it down, mouseEntered events are no longer called until the mouse button is lifted. So, when the mouseDown event is called, mouseEntered or MouseExited events are no longer called, nor is mouseDown called when rolling over other buttons until I let go of the initial mouseDown. So I would like to detect when

NSButton subclass as colorwell & preventing NSColorPanel from touching the first responder

末鹿安然 提交于 2019-12-07 11:25:41
I followed some examples for making an NSButton subclass work as an NSColorWell (since our NSButton subclass already gives us the appearance behavior we need), however I've noticed that after using the button to invoke the panel and changing the color, it's also changing the color of selected text in our document. If I instead subclassed NSColorWell with our appearance customizations, would it not have this problem? However, I'm still hoping for a work-around that avoids that & still lets us use our button subclass. I've seen discussion threads suggest letting the button itself become the

NSButton in NSTableCellView: How to find desired objectValue?

家住魔仙堡 提交于 2019-12-07 10:06:54
问题 I have a view-based NSTableView that is populated through bindings. My textFields & imageViews are bound to the NSTableCellView's objectValue's properties. If I want to have an edit/info button in my NSTableCellView: Who should be the target of the button's action? How would the target get the objectValue that is associated with the cell that the button is in? I'd ultimately like to show a popover/sheet based on the objectValue. 回答1: Your controller class can be the target. To get the object

NSButtonCell as Checkbox in a NSTableVIew don't get selected

微笑、不失礼 提交于 2019-12-07 06:09:04
问题 I have a NSTableVIew for multi-selection purposes with two columns, the first one with a NSButtonCell as checkbox and the other one as a title. The idea is to check the items to be added afterwords to an array. The problem is that the checkboxes don't change its state when I click them. I've tried to attach an IBAction but the sender to de action is the TableView but not the checkbox Any ideas (or link) about how to achieve this kind of functionality? 回答1: Going on the assumption you're using

how to set background color of NSButton OSX

[亡魂溺海] 提交于 2019-12-07 04:26:34
问题 I want to set the background color of NSButton.There was nothing in the attribute inspector so i was wondering if there was any way to do it programmatically? 回答1: System controls will need to follow the Apple look&feel, so you cannot easily change the background colour. If you want to accomplish this, you'll need to subclass NSButton and overwrite the drawRect: method. The downside is that you'll also need to handle the text drawing, and possibly different rendering based on button state.

Lost in NSButton types and alternate images

瘦欲@ 提交于 2019-12-07 03:37:22
问题 I’d like to have an NSButton with an image and an alternate image. The alternate image should be displayed while the button is being pressed and I’d also like to display the alternate image from code, calling something like [button setSelected:YES] . Is this possible without monkeing with the alternateImage property by hand? 回答1: This is possible without manually changing the button's image: In Interface Builder (xib/nib Editor) set the Type of NSButton to "Toggle" and the image will

Change NSButton's background color on highlight

不羁岁月 提交于 2019-12-07 01:55:27
问题 I have an NSButton which I want to have a different background color when it's highlighted than when it's not (transparent on not highlighted, if that makes any difference). At present, I have the following code [view setWantsLayer:YES]; NSButton* button = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; [button setBordered:FALSE]; [(NSButtonCell*)[button cell] setHighlightsBy:NSChangeBackgroundCellMask]; [view addSubview:button]; This will change the background to the default