nsbutton

Change direction of disclosure triangle

戏子无情 提交于 2019-12-11 11:13:52
问题 How can I change the direction of the disclosure triangle programmatically? In Interface Builder it's possible by changing the value "Control -> Layout" from "Left to Right" or "Right to Left". I made a diff of a NIB file. The only change was NSCellFlags2 . Is this documented anywhere? 回答1: The method you’re looking for is -[NSCell setUserInterfaceLayoutDirection:] . You need to obtain a reference to the corresponding cell and then send it the appropriate message. For example, considering

NSButton set background color macOS 10.12

可紊 提交于 2019-12-11 06:38:17
问题 I have NSButtons created in Storyboard that I would like to change the background color for. I have searched SO and Google but none of the solutions actually work on my project or even a simple test project. I've tried: Setting the button.layer.backgroundColor (including with and without importing QuartzCore and setting wantsLayer ). Getting the NSButtonCell from the NSButton and changing the background color. I've tried this with bordered, unbordered, transparent, etc. No change in

How to set focus to an NSButton?

女生的网名这么多〃 提交于 2019-12-10 20:11:58
问题 I'm writing a small menubar application for OS X Yosemite. When clicking on the menubar icon, a popover appears with a number of recessed buttons. Like so: As you can see, the "d4" button is focused, even though the d20 is selected by default. Clicking on any other button does not change the focus from the "d4" button. The only way to move the focus ring is via the Tab key. Here is my code from the popover view controller: import Cocoa class DiceRollerViewController: NSViewController { var

NSButton: show alternate image on hover

纵然是瞬间 提交于 2019-12-10 19:49:10
问题 I've a NSButton with both an Image and Alternate Image . I would like the alternate image to be shown on hover. To solve this, I've extended the NSButton to show the alternate image when hovering the view. Is there a better solution to this? My solution: @interface HoverButton() @property (nonatomic, strong) NSTrackingArea *trackingArea; @property (nonatomic, strong) NSImage *imageTmp; @end @implementation HoverButton -(void)mouseEntered:(NSEvent *)theEvent { [super mouseEntered:theEvent];

NSButton - set text color in disabled mode

徘徊边缘 提交于 2019-12-10 12:38:26
问题 For some reason, when my button is disabled, the text color turns white. I want it to stay black - how can i do that? 回答1: You can set text, image, colors, fonts, etc. for different status of a button: normal, highlighted, disabled, etc. You can do that in Interface Builder by changing the state with the dropdown list. 回答2: You can subclass NSButtonCell and override a method: - (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView { if (![self

How can I vertically align my status bar item text?

六眼飞鱼酱① 提交于 2019-12-10 02:39:58
问题 Left one on the picture is the date and time from Apple and one is my application one. As you may see the text of my application appears lower than the Apple one. Which doesn't look pretty. How can this be resolved? self.statusBarItem.image = nil self.statusBarItem.button?.imagePosition = .NoImage self.statusBarItem.button?.title = "Sun 5 Jun 13:35" 回答1: You could do it in offset. You cannot do it like this since it needs to be done on the status item button bar. button.frame = CGRectMake(0.0

(NSWindowButton) NSWindow.standardWindowButton button not highlighting

人走茶凉 提交于 2019-12-08 10:43:08
问题 When i use the following to create a button NSWindow.standardWindowButton(NSWindowButton.ZoomButton, forStyleMask: 0) I get a button that doesn't react to mouse hover events. I can augment this by creating a container view with a NSTrackingArea and manually triggering the highlight method but it produces a clicked state. Is there a way to somehow force the button into the expected behavior state without the darkened background? I have been trying to avoid subclassing NSButton , but it seems

Can't Change NSButton Font

醉酒当歌 提交于 2019-12-08 08:44:26
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 of other UI items to what the user's chosen. Additionally, I thought the problem was due to the fact

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

只愿长相守 提交于 2019-12-08 07:38:59
问题 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

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

半腔热情 提交于 2019-12-08 06:01:43
问题 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