Questions tagged [nstextfield]

NSTextField object belongs to Apple's class. It's a kind of NSControl that displays text that the user can edit or select.

An NSTextField object is a kind of NSControl () that displays text that the user can select or edit and that sends its action message to its target when the user presses the Return key while editing.

The NSTextField () class uses the NSTextFieldCell () class to implement its user interface.

References:

1028 questions
150
votes
7 answers

How do you set the text in an NSTextField?

I'm trying to set the text in an NSTextField, but the -setStringValue: and -setTitleWithMnemonic: methods are not working. Any ideas?
Alexsander Akers
  • 15,967
  • 12
  • 58
  • 83
106
votes
4 answers

Get value from NSTextField

I have an NSTextField and I need to get the field's value into a variable. What's the appropriate method?
anakin
  • 1,189
  • 2
  • 7
  • 8
56
votes
5 answers

Text change notification for an NSTextField

I would like to use the code from the answer to this question: How to observe the value of an NSTextField on an NSTextField in order to observe changes on the string stored in the NSTextField. [[NSNotificationCenter defaultCenter] …
alecail
  • 3,993
  • 4
  • 33
  • 52
48
votes
8 answers

NSTextField transparent background

I create transparent NSTextField self.myTextField = [[NSTextField alloc] initWithFrame:CGRectMake(backgroundView.frame.origin.x + backgroundView.frame.size.width + 20, self.projectTitle.frame.origin.y - 30.0, 100, 20)]; self.myTextField.editable =…
pawelropa
  • 1,409
  • 1
  • 14
  • 20
40
votes
3 answers

How to let NSTextField grow with the text in auto layout?

Auto layout in Lion should make it fairly simple to let a text field (and hence a label) grow with text it holds. The text field is set to wrap in Interface Builder. What is a simple and reliable way to do this?
Monolo
  • 18,205
  • 17
  • 69
  • 103
38
votes
8 answers

Objective c checking whether text field is empty

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…
objectiveccoder001
  • 2,981
  • 10
  • 48
  • 72
34
votes
2 answers

can't edit NSTextField in sheet at runtime

When clicking on a button, I'd like to display a sheet with an email+password prompt with options to save and cancel. The UI is all set up, the actions are in place, and the sheet appears and cancels as expected. The problem is that I can't edit…
Matt Stein
  • 3,053
  • 1
  • 19
  • 35
34
votes
1 answer

NSViewController User Interface State Restoration

Summary: What's the proper way to save/restore the state of an NSSearchField in my NSViewController using the built-in user interface preservation mechanism of Cocoa? Details: I'm working on my first macOS app and I'm having a little trouble with…
rmaddy
  • 314,917
  • 42
  • 532
  • 579
33
votes
1 answer

NSTextField, Change text in Swift

I can't seem to be able to change the text Label in a Mac app that I am trying to make. I am using swift. Here is the code I am using: @IBOutlet var sumlab: NSTextField! sumlab.text = "\(result.sum)" // result.sum is the result of a function I…
mohamad orabi
  • 325
  • 1
  • 3
  • 6
32
votes
1 answer

NSTextField or NSTextView?

Could someone explain to me what are the main differences between NSTextField and NSTextView? I know that NSTextView has more features and is usually used for longer texts, and NSTextField is usually used for one-line plain text fields, but if I…
Kuba Suder
  • 7,587
  • 9
  • 36
  • 39
29
votes
6 answers

Respond to mouse events in text field in view-based table view

I have text fields inside a custom view inside an NSOutlineView. Editing one of these cells requires a single click, a pause, and another single click. The first single click selects the table view row, and the second single click draws the cursor…
paulmelnikow
  • 16,895
  • 8
  • 63
  • 114
29
votes
10 answers

NSTextField - White text on black background, but black cursor

I've setup an NSTextField with text color as white, and the background color as (black despite not rendering the background color, so its transparent). All in Interface Builder. The problem I am having is the cursor is black, and hardly visible.…
mootymoots
  • 4,545
  • 9
  • 46
  • 74
29
votes
11 answers

Restrict NSTextField to only allow numbers

How do I restrict a NSTextField to allow only numbers/integers? I've found questions like this one, but they didn't help!
JomanJi
  • 1,407
  • 1
  • 17
  • 27
27
votes
7 answers

How to limit NSTextField text length and keep it always upper case?

Need to have an NSTextField with a text limit of 4 characters maximum and show always in upper case but can't figure out a good way of achieving that. I've tried to do it through a binding with a validation method but the validation only gets called…
Carlos Barbosa
  • 3,083
  • 5
  • 30
  • 30
26
votes
7 answers

Trouble matching the vibrant background of a Yosemite NSMenuItem containing a custom view

I am attempting to add a custom view to an NSMenuItem in the OS X 10.10 Yosemite menu bar. The custom view is simply an NSView background with an NSTextField “label”. The problem is that the background NSView is given Yosemite-style…
pkamb
  • 33,281
  • 23
  • 160
  • 191
1
2 3
68 69