Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why not just set the properties of the text field's <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/TextEditing/Tasks/FieldEditor.html" rel="noreferrer">field editor</a> directly when the field <a href="http://developer.apple.com/mac/library/documentation/cocoa/reference/ApplicationKit/Classes/NSResponder_Class/Reference/Reference.html#//apple_ref/occ/instm/NSResponder/becomeFirstResponder" rel="noreferrer">becomes first responder</a>? </p> <p>In a typical text field, selection is only visible when the field is first responder, so if you ask for the text field's field editor, then set <em>its</em> selected text attributes, you'd get the same affect, wouldn't you?</p> <pre><code>NSDictionary * attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSColor orangeColor], NSBackgroundColorAttributeName, nil]; NSTextView * fieldEditor = (NSTextView *)[[self window] fieldEditor:YES forObject:textField]; [fieldEditor setSelectedTextAttributes:attributes]; </code></pre> <p><strong>Note:</strong> As discussed in the comments below, the documentation is correct in saying the field editor is an instance of NSTextView, but the -[NSWindow fieldEditor:forObject:] method claims to return an NSText (NSTextView's immediate superclass). If you plan to send the field editor NSTextView-only methods, you'll need to cast it as an NSTextView to quiet the compiler's warnings. The casting won't break anything in your code, should the method prototype be corrected in the future, so it can safely be left in place.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload