nstextfield

NSTextField: end editing when user clicks outside of the text field

こ雲淡風輕ζ 提交于 2019-12-07 22:28:20
问题 I have an NSTextField that I'm setting editable depending on a user action. I'd like to end editing when the user clicks anywhere outside of the text field inside the window. Seems simple, but I could not get this to work. I implemented controlTextDidEndEditing and textDidEndEditing , but no luck, especially when I click on a user interface element that does not accept the first responder status. 回答1: Every NSEvent is pass through NSWindow's sendEvent: method. You can create a custom NSWindow

NSTextfield + NSMenu and first responder

杀马特。学长 韩版系。学妹 提交于 2019-12-07 04:21:21
问题 I'm trying to implement my own autocomplemention system (result is pull from an sqlite database) I've set up a NSTextField and the appropriate delegate. Each time the text in the NSTextField change, it call - (void)controlTextDidChange:(NSNotification *)aNotification method It work fine, in this method I build a menu programtically and finally I call/show it with that code: NSRect frame = [address frame]; NSPoint menuOrigin = [[address superview] convertPoint:NSMakePoint(frame.origin.x, frame

NSTextField's attributed string is delayed in rendering

爷,独闯天下 提交于 2019-12-07 03:19:35
问题 I've got an Label (NSTextField) in IB that's bound to a controller. The controller, on awakeFromNIB, sets the attributedStringValue of the label to contain some coloured text and a link or two. When you see the label it contains the correct string value, but some of the formatting is lost - until you click on the label, and it updates to contain the correct formatting. I'm using this code to set the value: [self.testTextField setAllowsEditingTextAttributes:YES]; [self.testTextField

NSTextField autocompletion delegate method not called

时光怂恿深爱的人放手 提交于 2019-12-06 22:34:07
问题 I implemented the following delegate method for NSTextField to add autocompletion support: - (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index The issue is that this method never gets called. I can verify that the delegate of the NSTextField is set properly because the other delegate methods function as they should. 回答1: You'll need to get complete: called on the

Set maximum characters (to one) in a NSTextfield in Swift

风流意气都作罢 提交于 2019-12-06 19:50:29
How do i set the maximum amount of characters in multiple NSTextfields (OSX cocoa app, NOT iOS) to one in Swift? Please explain how to do it, because I'm a complete newbie when it comes to OSX app development and therefore I don't understand short answers like "Use NSFormatter", because I have no idea what it is and how to implement it. Like Examples You don't need to limit the characters a user will enter just only look at the first character entered. In fact, it is probably better since you will always have to handle possible user errors. If you want to you can issue an alert that they

make nstextfield single line

六眼飞鱼酱① 提交于 2019-12-06 19:07:52
问题 how to make NSTextField really single line? I created a text field programmatically. when the return key is pressed, all text is selected. but I can still paste multiple lines of text. And when I press Arrow-right or Arrow down, it scroll to the next line. There aren't these issues if I use IB and set the "use single line mode", but I couldn't find the right method to set it programmatically. 回答1: Have you tried telling the field's cell to set whether it uses single-line mode? [myTextField

How to make a Multi-line (2 lines) label truncate the last line (OS X)

本秂侑毒 提交于 2019-12-06 13:52:22
I'm trying to make a multi-line label with 2 lines truncate the last line only. But it seems that, if I choose the Layout of that label as Truncates , my multi-line label becomes one-line. Here's what I want (I manually typed "..." for demonstration purposes): Here's what I have when I set my label as Truncates in IB (as you can see it still has 2 lines but acts as if it was only 1): Is this supposed to happen? If not, how can I achieve the truncate style of the first image? Thanks! It looks as though you must have Uses Single Line Mode checked, which should be unchecked. Also, under Layout is

Hiding the lupe icon of a NSSearchField

故事扮演 提交于 2019-12-06 13:50:36
I’m using a NSSearchField (not subclassed). When it’s not focused, the placeholderString is centered. But the lupe icon on the left appears a bit offset, so in fact the whole thing appears not to be centered. Is it possible to hide the lupe icon? There is not any direct access to the icon, so that a workaround is first access to the NSSearchField cell (casted as shown), and afterwards access to its button cell. self in this example is an instance of NSSearchField [(NSButtonCell *)[(NSSearchFieldCell *)self.cell searchButtonCell] setTransparent:YES]; Deafault Search Field: Hidden/Transparent

How do I update the expansion tooltip size after calling NSTextField setStringValue:?

孤者浪人 提交于 2019-12-06 13:25:31
When a view contains an NSTextField with the expansion tooltip enabled and the text doesn't fit, then the user hovers the cursor over the field, OS X shows an expansion tooltip. If you then call setStringValue: to change the text content of the NSTextField , the expansion tooltip's size is not updated. For instance, if the original text was 100 characters long but the new text is only 50 characters long, hovering over the new text will show an expansion tooltip large enough for 100 characters containing the new text. This is true even if the new string fits entirely in the NSTextField , which

Cocoa: Avoiding 'Updates Continuously' in control binds

别等时光非礼了梦想. 提交于 2019-12-06 11:28:07
I have several panels that contain NSTextField controls bound to properties within the File's Owner object. If the user edits a field and then presses Tab , to move to the next field, it works as expected. However if the user doesn't press Tab and just presses the OK button, the new value is not set in the File's Owner object. In order to workaround this I have set Updates Continuously in the binding, but this must be expensive (EDIT: or at least it's inelegant). Is there a way to force the bind update when the OK button is pressed rather than using Updates Continuously ? You're right that you