FAQ Database Discussion Community


Restrict input on NSTextField

osx,swift,cocoa,nstextfield
I want to restrict character input on NSTextField, i.e. so that disallowed characters aren't even appearing. Most of what I found about this topic were solutions that only validate after text input finished or using NSFormatter which still allows the character to appear. So far I came up with this...

Truncate beginning of label

cocoa,swift,nstextfield
I have a label (NSTextField) with text aligned right. When the text becomes too large to display, the end of the text is truncated (at the right edge of the label). In my case I would actually want to truncate the beginning of the text. How can I achieve this...

Cursor doesn't update in NSTextField as it autoresizes when resizing the enclosing NSWindow

objective-c,cocoa,nstextfield,autoresize,nscursor
I have an NSTextField that autoresizes. Its text is centered. When I start typing in the field and then resize the enclosing NSWindow, the cursor stays where it's at rather than repositioning to the appropriate place : I've also made an XCode project demonstrating this problem : https://www.dropbox.com/sh/cohhmslyl9ti43b/AAC6ULteopsQCMDsEArJU15Ta?dl=0 Does anyone...

Deselecting Text in NSTextField

objective-c,osx,nstextfield,deselect
Working on a new app, I'm running into the same problem described here in reguards to deselecting text that is input into an nstextfield: http://www.cocoabuilder.com/archive/cocoa/195313-nstextfield-how-to-deselect-text.html There are plenty of questions around SO about doing this with NSTextViews, but I haven't been able to find a working answer for NSTextFields. In...

How do I make a NSTextField grayed out?

cocoa,nstextfield
I have multiple text fields, and I was wondering how to make them grayed out I tried [textfield setEditable:NO] and [textfield setEnabled:NO] What am I missing? I connected the text field to a IBOutlet NSTextField *textfield;...

NSTextField GotFocus Event Cocoa Swift

cocoa,swift,events,focus,nstextfield
In swift Cocoa is there an event that fires when a NSTextField gets focus for editing. I Come from C# which has GotFocus() and LostFocus() Events. For NSTextfield I could find only these functions which fire after one starts typing. Not as soon as focus is gained. override func controlTextDidBeginEditing(obj:...

NSTextField - actions within *textField

objective-c,cocoa,nstextfield
I need help using NSTextField and its inputs/outputs. In a functioning code I have three different NSTextFields (in Cocoa + Obj-C) I know how calculate result from more integer inputs... --- AppController.h --- @interface AppController : NSObject { IBOutlet NSTextField *firsTextField; // 1st Outlet IBOutlet NSTextField *secondTextField; // 2nd Outlet...

NSTableView textfield cell should not go into edit on click

osx,swift,cocoa,nstableview,nstextfield
I have two NSTableViews in my app and both are set up the same, same parameters, etc., they have several columns with NSTextField cells and the first column is editable. The first table behaves like I want it: if the user clicks, the row is selected. If the user clicks...

Use a text field to set the value of a variable

objective-c,cocoa,xcode4,nstextfield
I have a few NSTextFields in my XIB. I created the action for one of my text fields, and it looks like - (IBAction)setXPos:(id)sender; In my AppDelegate.h file, I also created an int named XPos. In my AppDelegate.m file, I am having trouble setting the value of XPos to be...

How to I set the text in a textField? [duplicate]

objective-c,cocoa,nstextfield
This question already has an answer here: Reset NSTextField's text to empty string — setText: doesn't work 2 answers I have a text field, and I made a reset button for my app. I want the reset button to set the text of the text field to @"", or...

cocoa osx add nstextfields programatically

osx,cocoa,constraints,nsview,nstextfield
Im making a project for osx and i need to add multiple NSTextfields to a custom view (NSView) programatically. I dont know how to achieve this correctly. This is what i need to do: I know how to create the NSTextfiedls and how to add them to the NSView, but...

When using NSTextFieldDelegate's – control:textView:doCommandBySelector: how do we allow/make normal performance of e.g. backspace?

cocoa,delegates,nstextfield
In another SO thread (Execute an Action when the Enter-Key is pressed in a NSTextField?) I saw this suggested code for executing an action on pressing Enter in an NSTextField: (void)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector { NSLog(@"Selector method is (%@)", NSStringFromSelector( commandSelector ) ); if (commandSelector == @selector(insertNewline:)) { //Do...

Setting editable on a NSTextField doesn't have any effect

osx,cocoa,cocoa-bindings,nstextfield
I have an NSTextField in a view that is bound to a value in the view's view controller. When a button is pressed I wish to make the text field no longer editable so I use the following code: - (IBAction)makeTextFieldNotEditable:(id)sender { self.textField.editable = NO; } Everything is bound correctly...

Unexpected NSTextField background color, should be transparent

cocoa,swift,gradient,nswindow,nstextfield
UPDATE: I've added a sample project for testing, see at the bottom of the post. ORIGINAL QUESTION: I've got an NSWindow and I change its background when some other parameters change. The window background is a gradient I'm drawing by overriding drawRect in a subclass of the window's view. class...

Automatically resizing labels

objective-c,cocoa,swift,nstextfield
I am trying to create an interface where two labels share a space, similar to an html table with two columns would: there is a distance between the two and when the window is resized they both resize and stay the same size, keeping the distance between them and filling...

Change NSTextField border and BG color while editing

osx,swift,cocoa,nstextfield
I have a NSTextField that uses no border and window background color while it is displayed but I want it to change to have the default border and white BG color when being edited. I know I can change these properties with: nameTextField.bezeled = true nameTextField.backgroundColor = NSColor.textBackgroundColor() What I...

Why does the intrinsicContentSize of my NSTextField not change as I enter characters?

cocoa,autolayout,nstextfield
I am trying to achieve a custom NSTextField that resizes horizontally (without wrapping text) as text is added to the NSTextField. The Content Compression Resistance Priority property should be able to assist in the above (I have set this to 1000) but it is actually having no effect. That gets...

How to intercept keystrokes from within the field editor of an NSTextField?

cocoa,nstextfield,appkit,nsresponder
Intro When my custom NSTextField is in "text editing mode" and the field editor has been placed in front of it as firstResponder I no longer get the keystrokes through NSTextField.keyDown(...). I understand that the keystrokes are now being routed through the field editor. Most online recommendations are to override...

Capture the space key in a window containing several NSTextFields

objective-c,osx,cocoa,keyboard-events,nstextfield
I have a large window with a number of NSTextField fields on it, and I would like to intercept the space bar even while any of the text fields have focus, so that pressing space at any time will cause a separate action. Subclassing NSTextField and overriding -keyUp: allows me...

How to distinguish between a label and a textfield in cocoa application?

objective-c,cocoa,label,nstextfield
I want to have a collection of all of my textfields in my view: for ( NSView* view in [self.view subviews]) { if ([view isKindOfClass:[NSTextField class]]){ [self.allTxtFields addObject:view]; } } problem is, that Labels are happened to be NSTextField too! how can I differ a textfield from label?...

NSBorderlessWindowMask Subview NSTextfield not keybard editable Swift

xcode,swift,nswindow,nstextfield,keywindow
I'm using a NSBorderlessWindowMask for my main window on a Swift project (without storyboards), when I load a Subview, the NSTextfield outlet is not keybard editable. I already put this code on the initialisation: self.window?.makeKeyWindow() self.window?.becomeKeyWindow() this allows the outlet to be "blue" like on focus, but the keyboard editing...

Change color of NSTextField

swift,cocoa,nstextfield
I'm trying to code an easy example to modify the color of a NSTextfield playing with green and red colors as good answer or wrong. I cannot achieve that cause i always obtained an error message when using this apple guide page for NSTextField, AppKit framework ref. I'm trying to...