• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to blink with a focus ring of the text box?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to blink with a focus ring of the text box?


  • Subject: Re: How to blink with a focus ring of the text box?
  • From: Peter <email@hidden>
  • Date: Thu, 06 Oct 2011 18:06:21 +0200

Adding to my own post I just found this in my snippets collection:

This listing shows how you draw such a focus ring. It requires you to override the NSCell drawWithFrame:inView: In this method, if the cell is supposed to draw evidence of first-responder status, set the rectangle for the focus ring, call NSSetFocusRingStyle with an argument of NSFocusRingOnly, and then create and fill a bezier path defining that rectangle. Filling in this case simply draws the ring.

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
{
    // other stuff might happen here
    if ([self showsFirstResponder]) {
         // showsFirstResponder is set for us by the NSControl that is drawing  us.
        NSRect focusRingFrame = cellFrame;
        focusRingFrame.size.height -= 2.0f;
        [NSGraphicsContextsaveGraphicsState];
        NSSetFocusRingStyle(NSFocusRingOnly);
        [[NSBezierPath bezierPathWithRect: NSInsetRect(focusRingFrame, 4.0f, 4.0f)] fill];
        [NSGraphicsContext restoreGraphicsState];
    }
    // other stuff might happen here
}

So possibly you could create your own NSTextFieldCell, set your NSTextField to use it, call [super drawWithFrame.....] somewhere in the above method to do the standard drawing and move on from there. The flashing could be implemented using a CALayer animation or something.

If you manage to implement this you should make it open source :-) since I guess it's quite a bit of work to get it done.

> Read carefully:
>
> The original poster stated: "any more text" - or are you suggesting that he should disable the text box when a certain number of characters are reached? I guess not.
>
> AFAIK, the focus ring is not accessible programmatically, except form setting it by making something the first responder.
>
> You could use a text formatter or one of the validation methods and simply stop accepting key strokes, change the text color to red and/or display an alert.
>
> Am 06.10.2011 um 17:43 schrieb Thomas Davie:
>
>> The correct way to notify a user that he can't enter text in a text box is to disabled it.
>>
>> Bob
>> if (*ra4 != 0xffc78948) { return false; }
>>
>> On 6 Oct 2011, at 16:33, Nick wrote:
>>
>>> Hello
>>> I am wondering if there's a way to do this, notifying the user that he can't
>>> enter any more text into NSTextField edit box?
>>> Is there a way to change the color of the NSTextField's focus ring to red
>>> (to highlight that this is an error)?
>>> How difficult would that be to implement?
>>> Thank you!
>>> _______________________________________________
>>>
>>> Cocoa-dev mailing list (email@hidden)
>>>
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>
>>> Help/Unsubscribe/Update your Subscription:
>>>
>>> This email sent to email@hidden
>>
> _______________________________________________

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >How to blink with a focus ring of the text box? (From: Nick <email@hidden>)
 >Re: How to blink with a focus ring of the text box? (From: Thomas Davie <email@hidden>)

  • Prev by Date: Re: How to blink with a focus ring of the text box?
  • Next by Date: Re: How to blink with a focus ring of the text box?
  • Previous by thread: Re: How to blink with a focus ring of the text box?
  • Next by thread: Re: How to blink with a focus ring of the text box?
  • Index(es):
    • Date
    • Thread