nstextfield

How to live check a NSTextField - Swift OS X

梦想的初衷 提交于 2019-12-19 21:19:03
问题 I am currently making an OS X application written in Swift. What I want to do is when the user enters text in a NSTextField , I want to run a function that checks the value and adds it to a Label. How would I do this in swift? 回答1: Conforms ViewController to protocol NSTextDelegate . Assign ViewController as Delegate for TextField . Implement controlTextDidChange method. import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate { @IBOutlet weak

NSTextField or NSTextView?

徘徊边缘 提交于 2019-12-18 10:42:24
问题 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 understand correctly, NSTextField can be also used with attributed strings and with multiple lines... What I need specifically is a control that would display the text of messages inside a timeline view like in Tweetie or any other similar software.

Swift: Set Insertion Point in NSTextField

别等时光非礼了梦想. 提交于 2019-12-18 09:37:39
问题 I have a NSTextField with some text "sometext". How can I place the cursor between e and t: "some|text" programmatically? 回答1: You need to set your text field current editor selected range property. Try like this: textField.currentEditor()?.selectedRange = NSRange(location: 4, length: 0) You will need to call displayIfNeeded textField.displayIfNeeded() 来源: https://stackoverflow.com/questions/34246319/swift-set-insertion-point-in-nstextfield

Change NSTextField font size to fit

杀马特。学长 韩版系。学妹 提交于 2019-12-18 06:22:19
问题 Is there anything like the UILabel's adjustsFontSizeToFitWidth that can be used with a NSTextField? 回答1: In short: no. You have to do some brute force work to determine a string's -sizeWithAttributes: -boundingRectWithSize:options:attributes: with a given font size (set as an NSFont for NSFontAttributeName). I'd start with a standard system font size and work down or up from there, depending on whether it's smaller or larger than the desired rectangle. 回答2: Swift 4 solution: It will resize

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

浪子不回头ぞ 提交于 2019-12-17 22:58:20
问题 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 vibrancy/transparency when added to the menu. The NSTextfield label is not. Through the use of NSRectFillUsingOperation I've gotten this to look good for some background colors in Yosemite. But others continue to not match. When it is working, after manually

NSTextField: exposing its Copy and Paste methods

北城以北 提交于 2019-12-17 20:55:52
问题 I am trying to access the copy, cut, and paste methods of a NSTextField instance in its window delegate so I can customize these methods. I find that unlike tableViews and textViews, the textfield's copy, paste and cut actions are not responsive in the delegate. My understanding is that all text controls share the window's field editor yet this does not seem to be the case. I thought perhaps the TextField's field editor was not being shared with the window delegate, however I did some testing

How to make NSSearchField send action upon autocompletion?

流过昼夜 提交于 2019-12-17 19:43:29
问题 This question seems straightforward but I've tried everything I can think of, and Googled for hours. I have an NSSearchField that does autocomplete, basically copying Apple's SearchField sample code. I have turned off "Sends Whole Search String" in IB because I don't want to do the search until the user has finalized their text entry, and don't want to do multiple searches (they are expensive). As the user types in the field, when they press enter, specifying that they accept the current

How do you set the text in an NSTextField?

点点圈 提交于 2019-12-17 18:09:12
问题 I'm trying to set the text in an NSTextField, but the -setStringValue: and -setTitleWithMnemonic: methods are not working. Any ideas? 回答1: setStringValue: is the way to do it. You should make sure your outlet is being set properly. (In the debugger, make sure your textfield variable is not null.) 回答2: Just do something like this: myLabel.stringValue = @"My Cool Text"; 回答3: Just myLabel.stringValue = "MY TEXT" works here, using Swift and Xcode 6. 回答4: Swift 4 self.yourTextField.stringValue =

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

落花浮王杯 提交于 2019-12-17 15:29:50
问题 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 in the field. Double-clicking the cell, which lets you edit in a cell-based table view, only selects the row. The behavior I want: one click to change the selection and edit. What do I need to override to obtain this behavior? I've read some other

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

心不动则不痛 提交于 2019-12-17 08:48:35
问题 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 when the control loses first responder and that's no good. Temporarly I made it work by observing the notification NSControlTextDidChangeNotification on the text field and having it call the method: - (void)textDidChange:(NSNotification*