nsbutton

Disable/Enable NSButton if NSTextfield is empty or not

馋奶兔 提交于 2019-12-03 06:05:39
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]; } else { [myButton setEnabled: NO]; } } But nothing happens... I´ve tried to set the appDelegate as the

Simple mouseover effect on NSButton

二次信任 提交于 2019-12-02 22:39:37
I am creating a custom NSButtonCell for a custom rendering. Now, I want to have different aspect depending if the mouse is over the button or not. How can I get this information? Thanks and regards, Here is i have created and worked for me perfectly... Step 1: Create the Button with tracking area NSButton *myButton = [[NSButton alloc] initWithFrame:NSMakeRect(100, 7, 100, 50)]; [myButton setTitle:@"sample"]; [self.window.contentView addSubview:myButton]; // Insert code here to initialize your application NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:[myButton bounds]

NSButton subclass that responds to right clicks

不羁岁月 提交于 2019-12-01 19:44:53
问题 I have an NSButton subclass that I would like to make work with right mouse button clicks. Just overloading -rightMouseDown: won't cut it, as I would like the same kind of behaviour as for regular clicks (e.g. the button is pushed down, the user can cancel by leaving the button, the action is sent when the mouse is released, etc.). What I have tried so far is overloading -rightMouse{Down,Up,Dragged} , changing the events to indicate the left mouse button clicks and then sending it to -mouse

Make NSButton open fonts panel

两盒软妹~` 提交于 2019-12-01 16:46:30
问题 I was wondering how to go about making a button open up the fonts panel in Mac OS X using Cocoa, I have an NSTextView in my application and want the fonts dialogue to display when the user clicks the button. Thanks in advance! 回答1: The last object that comes by default (those one that you see in the left from the editing area) is exactly the Font Manager. All you have to do is to control drag from your button to the font manager and connect the orderFrontFontPanel: action. 来源: https:/

Swift Mac OSX NSButton title color

北城以北 提交于 2019-12-01 16:30:53
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? bluedome 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 ]) Swift 4 I've added this as an additional answer since it changes only the requested attribute without

Click a NSPushButton programmatically with “animation”

回眸只為那壹抹淺笑 提交于 2019-12-01 07:33:19
I just ran into a problem I already know from other programming languages/frameworks .... Whenever the user clicks a certain button on the keyboard, he triggers the same action than when a certain button in the GUI is pressed. ( Some guys call these "shortcuts" ;D ) To give the user an optical feedback, I would like to sorta "click" the button programmatically rather than calling the same functions that get called when the button is clicked. If I set the button as a key equivalent in IB, it looks exactly as I want to have it. Can't do that here as the shortcut should just be enabled if the

NSButton setAction selector

杀马特。学长 韩版系。学妹 提交于 2019-12-01 07:16:52
I just want to add a NSButton with setAction Arguments. NSRect frame = NSMakeRect(10, 40, 90, 40); NSButton* pushButton = [[NSButton alloc] initWithFrame: frame]; [pushButton setTarget:self]; [pushButton setAction:@selector(myAction:)]; But I want to put an argument to the function myAction... How ? Thanks. But I want to put an argument to the function myAction... How ? You can't. … if there is more than one button that uses this method, we can not differentiate the sender (only with title)... There are three ways to tell which button (or other control) is talking to you: Assign each button

NSButton setAction selector

断了今生、忘了曾经 提交于 2019-12-01 04:25:56
问题 I just want to add a NSButton with setAction Arguments. NSRect frame = NSMakeRect(10, 40, 90, 40); NSButton* pushButton = [[NSButton alloc] initWithFrame: frame]; [pushButton setTarget:self]; [pushButton setAction:@selector(myAction:)]; But I want to put an argument to the function myAction... How ? Thanks. 回答1: But I want to put an argument to the function myAction... How ? You can't. … if there is more than one button that uses this method, we can not differentiate the sender (only with

Cocoa forControlEvents:WHATGOESHERE

好久不见. 提交于 2019-12-01 00:30:23
In Cocoa/Objective-C if I have created a button programmatically, what do I put in for my control event? [btnMakeChar addTarget:self action:@selector(makeChar:) forControlEvents:WHAT GOES HERE?]; In iOS you can write it like so forControlEvents: UIControlEventTouchUpInside I can't find anything to show what I would use for just cocoa, not cocoa touch I'm not sure if I understand you correctly, but if you're programming a Mac, [theHappyButton setTarget:self]; [theHappyButton setAction:@selector(doStuff)]; it is two separate lines, rather than the one combined line of code on an iPhone. I hope

How to show a keyboard via press a NSButton?

落花浮王杯 提交于 2019-11-30 18:35:50
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~ Constantin 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 remove the UITextField with removeFromSuperview . Maybe a little bit dirty, but thats the