nsbutton

Disable/Enable NSButton if NSTextfield is empty or not

瘦欲@ 提交于 2020-01-01 02:29:10
问题 I´m newbie with cocoa. I have a button and a textField in my app. I want the button disabled when the textfield is empty and enabled when the user type something. Any point to start? Any "magic" binding in Interface Builder? Thanks [EDITED] I´ve tried to set the appDelegate as the NSTextfield´s delegate and added this method (myTextfield and myButton are IBOutlets): - (void)textDidChange:(NSNotification *)aNotification { if ([[myTextField stringValue]length]>0) { [myButton setEnabled: YES]; }

PaintCode NSButton displays upside-down

前提是你 提交于 2019-12-24 12:28:38
问题 I am using PaintCode to create a button. I import the StyleKit, and create the NSButton Class for my RankView button. Like this: import Cocoa @IBDesignable class RankView: NSButton { override func drawRect(dirtyRect: NSRect) { super.drawRect(dirtyRect) StyleKit.drawRank2() // Drawing code here. } } But when I run the app, (and even in the storyboard), the button is upside-down. Like this: The arrow should be Up, but it points down. Whenever I change the parent class to NSView it displays

Non-square NSButton

旧时模样 提交于 2019-12-23 16:28:23
问题 How to create a NSButton with non-square "hit area"? Example: Thanks. 回答1: You could probably subclass NSButton and override hitTest: to return nil when outside the area you want to be clickable. (Return [super hitTest:] when inside.) Docs here. 来源: https://stackoverflow.com/questions/10313938/non-square-nsbutton

How to NOT highlight the NSButton's template image when clicked?

跟風遠走 提交于 2019-12-23 07:48:42
问题 I have NSButtons in each row of a NSTableView. The buttons images are set in IB and are black icons with alpha channel: The windows are set to dark mode with: window?.appearance = NSAppearance(named: NSAppearanceNameVibrantDark) And to normal mode with: window?.appearance = nil The goal is that the buttons should be black when the window is white, and should be white when the window is dark, without changing when clicked. In dark mode, in order to achieve the color change, I set the button's

Custom NSButtonCell, drawBezelWithFrame not called

断了今生、忘了曾经 提交于 2019-12-23 02:17:29
问题 I'm trying to figure out how to custom draw Buttons in Cocoa/OSX. Since my view is custom drawn I will not use IB and want to do it all in code. I created a subclass of NSButtonCell and a subclass of NSButton. In the Subclass of NSButtonCell I override the Method drawBezelWithFrame:inView: and in the initWithFrame Method of my subclassed NSButton I use setCell to set my CustomCell in the Button. However, drawBezelWithFrame gets not called and I don't understand why. Can someone point out what

Key Value Observing and NSButton state

风格不统一 提交于 2019-12-22 10:49:12
问题 I'm trying to observe checkbox status and make appropriate changes in the app when checkbox status changes. In a window manager that manages the window with checkbox I have following observer setup: - (void)awakeFromNib { [myCheckBox addObserver:self forKeyPath:@"state" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL]; } - (void)dealloc { [myCheckBox removeObserver:self forKeyPath:@"state"]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id

NSButton with delayed NSMenu - Objective-C/Cocoa

折月煮酒 提交于 2019-12-22 04:09:32
问题 I want to create an NSButton that sends an action when it is clicked, but when it is pressed for 1 or two seconds it show a NSMenu. Exactly the same as this question here, but since that answer doesn't solve my problem, I decided to ask again. As an example, go to Finder, open a new window, navigate through some folders and then click the back button: you go to the previous folder. Now click and hold the back button: a menu is displayed. I don't know how to do this with a NSPopUpButton . 回答1:

Swift Mac OSX NSButton title color

血红的双手。 提交于 2019-12-19 17:42:30
问题 I would like to know how to change title color to a NSButton in swift, I've seen lots of examples in objective-c but I think in swift the implementation is different, can anyone provide me an example? 回答1: try this in viewDidLoad or somewhere. In Swift 3: let pstyle = NSMutableParagraphStyle() pstyle.alignment = .center button.attributedTitle = NSAttributedString(string: "Title", attributes: [ NSForegroundColorAttributeName : NSColor.red, NSParagraphStyleAttributeName : pstyle ]) 回答2: Swift 4

How to show a keyboard via press a NSButton?

泪湿孤枕 提交于 2019-12-18 20:09:17
问题 I only know few ways to show a keyboard on iOS touch textfield,search bar,textview..... Is it can via touch a button to show keyboard ??? I wish I can use this way to set a button tittle if the button is no tittle or can rename it. Thank you guys~ 回答1: You need to add an UITextField to your view and call then [myTextfield becomeFirstResponder]; Its possible to set the hidden attrribute from UITextField to YES - so the user will never see the textfield. After Keyboard input is finished you can

NSButton how to color the text

╄→尐↘猪︶ㄣ 提交于 2019-12-17 17:37:19
问题 on OSX I have an NSButton with a pretty dark image and unfortunately it is not possible to change the color using the attributes inspector. See picture the big black button, the text is Go . Any clues for a possibility to change the text color? I looked in to the NSButton class but there is no method to do that. I´m aware that I could make the image with white font but that is not what I want to do. Greetings from Switzerland, Ronald Hofmann --- 回答1: Here is two other solutions: http://denis