nstextfield

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

你离开我真会死。 提交于 2019-12-06 11:11:19
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. Every NSEvent is pass through NSWindow's sendEvent: method. You can create a custom NSWindow and override the sendEvent: method. If there is a mouse down event, broadcast it by the

NSTextField clicked link colour

烂漫一生 提交于 2019-12-06 10:59:38
I have an NSTextField that contains an NSAttributedString which itself contains a clickable link. I've change the colour of the link for my own styling, however when I click on it it becomes blue and underlined. How can I stop this? Seems that I'm not the only one with this problem, and there's a handy class to solve it: https://github.com/laevandus/NSTextFieldHyperlinks This ( http://developer.apple.com/library/mac/#qa/qa1487/_index.html ) may help you. It will show you how to set/change the blue link color and the underlineAttribute. You may also have a look at the methods

Anyway to make a (wrapping) NSTextField write a carriage return upon pressing return key?

寵の児 提交于 2019-12-06 10:27:47
问题 I want to use a wrapping text field that can potentially contain carriage returns in my app. Is there any way to force the NSTextField object to write a carriage return into the text area instead of sending its action to its target when the Return key is pressed? 回答1: This is covered in Technical Q&A QA1454, which also enumerates reasons why one would use NSTextField instead of NSTextView in this case. You can implement the following method in the text field delegate: - (BOOL)control:

NSStatusItem with NSPopover and NSTextField

夙愿已清 提交于 2019-12-06 10:23:49
问题 I have a NSStatusItem that displays a NSPopover which contains a NSTextField but the text field isn't editable although it has been so be so in Xcode. Now this is a known bug and there is apparently a solution someone posted here. I really need to work around this bug. I'll just quote the answer here for convenience: The main problem is the way keyboard events works. Although the NSTextField (and all his superviews) receives keyboard events, he doesn't make any action. That happens because

NSTextField with suggestions drop-down

六眼飞鱼酱① 提交于 2019-12-06 09:20:48
Instead of implementing my own, I am looking into reusing an existing custom NSTextField that has support for suggestions drop-down - Same as the one in the browser as you type you get a list of suggestions underneath. Do you know any good ones? Thank you! They're called completions. You still use a regular text field but add this: control:textView:completions:forPartialWordRange:indexOfSelectedItem The biggest problem is you need to provide the list of words that can be autocompleted. 来源: https://stackoverflow.com/questions/6725359/nstextfield-with-suggestions-drop-down

Highlight a selection in NSTextField

好久不见. 提交于 2019-12-06 08:16:50
I want to be able to highlight a portion of text in an NSTextField but I've not been able to Google a way of doing this. I have defined an NSRange but I cannot find a way of using this range to highlight the text. The only thing I have turned up is textField.selectText but this supposedly highlights the whole field. I'm using Swift 2. JWWalker You may have noticed that an NSTextField only shows a selection range when it has focus, i.e., is the first responder. In this case, editing is handled by an NSTextView called the field editor. So, make sure the field has focus (e.g., by using the

Why do hyperlinks sometimes not show in an NSTextField with an NSAttributedString?

天大地大妈咪最大 提交于 2019-12-06 03:04:31
问题 The text I use in an NSTextField is loaded from a file as follows. NSString *path = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]; NSAttributedString *as = [[NSAttributedString alloc] initWithPath:path documentAttributes:NULL]; [creditsLabel setAttributedStringValue:as]; [creditsLabel becomeFirstResponder]; The hyperlinks in the window don't render in blue underline unless I first click somewhere on the NSTextField, as per the two screenshots. How can I make these

NSTextField (Label) Attributed Text: Select

时光怂恿深爱的人放手 提交于 2019-12-06 02:10:43
问题 I have a NSTextField Label that has attributed text in it. The color and size are different from the defaults. (The text is a bit larger and green) Now, I need to be able to select the text in the label so as the click the hyperlinks embedded in the attributed text. This works fine; however, when selecting the text the format of the text reverts back to the defaults (a smaller, black font). Is there anyway to stop this behavior so that my styling is preserved when the user clicks (selects

Suppressing the text completion dropdown for an NSTextField

谁说我不能喝 提交于 2019-12-05 22:16:07
I'm trying to create the effect of an NSComboBox with completes == YES, no button, and numberOfVisibleItems == 0 (for an example, try filling in an Album or Artist in iTunes's Get Info window). To accomplish this, I'm using an NSTextField control, which autocompletes on -controlTextDidChange: to call -[NSTextField complete:] , which triggers the delegate method: - (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index; I've gotten this working correctly, the only problem

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

谁说我不能喝 提交于 2019-12-05 12:40:14
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 the following method within the delegate of the custom NSTextField : control(_:textView:doCommandBySelector:) I have indeed overridden this method but it doesn't seem to get called? See code below: class FocusDelegate: NSObject, NSTextFieldDelegate{ func control(control: