nstextfield

Change border color of NSTextField

≡放荡痞女 提交于 2019-12-03 06:31:07
I want to change the border color of NSTextField object, but I can't achieve it. I already have tried many solutions EX: be subclass, draw background... is there anyone who can resolve this issue or share any ideas? Please let me know. Many thanks. Use NSBezierPath - (void)drawRect:(NSRect)dirtyRect { NSPoint origin = { 0.0,0.0 }; NSRect rect; rect.origin = origin; rect.size.width = [self bounds].size.width; rect.size.height = [self bounds].size.height; NSBezierPath * path; path = [NSBezierPath bezierPathWithRect:rect]; [path setLineWidth:2]; [[NSColor colorWithCalibratedWhite:1.0 alpha:0.394]

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

Add shadow (recessed text effect) to Cocoa label without degrading text rendering quality

核能气质少年 提交于 2019-12-03 05:08:49
问题 I'd like to create statusbar with text effect like in Safari or iTunes, i.e. recessed text. However, if I simply add shadow in Interface Builder using Core Animation panel, OS X's worst text rendering kicks in: What's the trick to get recessed text on a label and keep proper subpixel rendering? 回答1: There is a built-in way to do this: [[yourTextField cell] setBackgroundStyle:NSBackgroundStyleRaised]; 回答2: It's a cheap old trick: You draw the text in white at an offset and then draw the black

selectText of NSTextField on focus

北城余情 提交于 2019-12-03 01:02:51
Could anybody suggest a method to select all the text of an NSTextField when the user clicks it? I did find suggestions to subclass NSTextField and then use mouseDown or firstResponder ,` but it's beyond my skill for now. So I was hoping either there would be an easier solution or somebody might be kind enough to detail the steps required. There isn't an easier solution, you need to subclass NSTextField to do what you want. You will need to learn how to handle subclassing if you are to do anything useful in Cocoa. Text fields can be relatively complex to subclass because an NSTextField uses a

Objective c checking whether text field is empty

一笑奈何 提交于 2019-12-03 00:59:48
Here's the code: - (IBAction) charlieInputText:(id)sender { //getting value from text field when entered charlieInputSelf = [sender stringValue]; if (charlieInputSelf != @"") { //(send field if not empty } } This sends it even when the field is empty; therefore, this does not work as I want it to. Simply checks for nil and if length of text length is greater than 0 - not empty if (textField.text && textField.text.length > 0) { /* not empty - do something */ } else { /* what ever */ } We already have inbuilt method that return boolean value that indicates whether the text-entry objects has any

Add shadow (recessed text effect) to Cocoa label without degrading text rendering quality

二次信任 提交于 2019-12-02 18:24:02
I'd like to create statusbar with text effect like in Safari or iTunes, i.e. recessed text. However, if I simply add shadow in Interface Builder using Core Animation panel, OS X's worst text rendering kicks in: What's the trick to get recessed text on a label and keep proper subpixel rendering? There is a built-in way to do this: [[yourTextField cell] setBackgroundStyle:NSBackgroundStyleRaised]; It's a cheap old trick: You draw the text in white at an offset and then draw the black text on top of it. There is a hook for shadows in the text-drawing system, NSAttributedString's

Trouble with NSTextField in Swift using xcode 6.1 (OSX)

夙愿已清 提交于 2019-12-02 13:18:06
I started Swift but not Objective C. Can someone teach me how to get and set the NSTextField in Swift using xcode 6.1 under OSX? You get and set the value of an NSTextField with the stringValue property. For instance, if you have this @IBOutlet in your app: @IBOutlet weak var textfield: NSTextField! getting the value: println("textfield is \(textfield.stringValue)") setting the value: textfield.stringValue = "this is my string" 来源: https://stackoverflow.com/questions/27163375/trouble-with-nstextfield-in-swift-using-xcode-6-1-osx

Reset NSTextField's text to empty string — setText: doesn't work

徘徊边缘 提交于 2019-12-02 08:01:42
问题 I have an NSTextField , and I need a button to reset the text of the field. How would I do that? I have been trying this: [textBox setText:@""]; textbox.text = @""; That does not work, but I have researched, and found nothing on how to set the text, only how to get the text. 回答1: If it is OSX and NSTextField then use : [textBox setStringValue:@""]; 回答2: Try this code: theLabel.text = @"this is some text"; [self.view addSubView:theLabel]; Here, the label is the text field. 来源: https:/

Secure text .echosbullets not working for password field

白昼怎懂夜的黑 提交于 2019-12-02 06:48:27
Here's what I've got: @IBOutlet weak var password: NSSecureTextField! @IBOutlet weak var shwpswd: NSButton! //Checkbox @IBOutlet weak var pswdcell: NSSecureTextFieldCell! //Cell @IBAction func shwpswd(_ sender: Any) { if(shwpswd.state == 1) { pswdcell.echosBullets = false // Turn the Secure text into regular text } else if(shwpswd.state == 0) { pswdcell.echosBullets = true // Secure text } } Everything seems to run fine, except the text in the password field doesn't change states between echoing bullets and echoing the real text. Everything is linked together properly too - Cell is within the

Recognize if user has pressed arrow key while editing NSTextField swift

泄露秘密 提交于 2019-12-02 06:36:00
问题 I have many NSTextFields and I want to know, if the user has pressed one of the arrow keys while editing one of them. The function override func keyDown(theEvent: NSEvent) { switch theEvent.character { case NSRightArrowFunctionKey: println(1) moveGor(NSRightArrowFunctionKey) case NSLeftArrowFunctionKey: moveGor(NSLeftArrowFunctionKey) case NSUpArrowFunctionKey: moveVert(NSUpArrowFunctionKey) case NSDownArrowFunctionKey: moveVert(NSDownArrowFunctionKey) default: super.keyDown(theEvent) } }