Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:17:04+00:00 2026-06-13T22:17:04+00:00

I am working on creating some custom Cocoa components. Currently I’m trying to figure

  • 0

I am working on creating some custom Cocoa components. Currently I’m trying to figure out how to draw custom NSTextFields.

I have overridden the drawRect method on my subclass but when i start typing, i get a double rectangle like this https://i.stack.imgur.com/5FSYA.jpg.

Here is my drawRect method

- (void)drawRect:(NSRect)dirtyRect
{
    [NSGraphicsContext saveGraphicsState];
    [[NSBezierPath bezierPathWithRoundedRect:dirtyRect xRadius:5.0f yRadius:5.0f] setClip];
    [[NSColor grayColor] setFill];
    NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
    [NSGraphicsContext restoreGraphicsState];

    [NSGraphicsContext saveGraphicsState];
    NSRect rect = NSInsetRect(dirtyRect, 1.0f, 1.0f);
    [[NSBezierPath bezierPathWithRoundedRect:rect xRadius:5.0f yRadius:5.0f] setClip];
    [[NSColor whiteColor] setFill];
    NSRectFillUsingOperation(rect, NSCompositeSourceOver);
    [NSGraphicsContext restoreGraphicsState];
}

UPDATE:

I moved my drawing code into a NSTextFieldCell subclass as so

- (void)drawWithFrame:(NSRect)frame inView:(NSView *)controlView {
    [NSGraphicsContext saveGraphicsState];
    [[NSBezierPath bezierPathWithRoundedRect:frame xRadius:5.0f yRadius:5.0f] setClip];
    [[NSColor grayColor] setFill];
    NSRectFillUsingOperation(frame, NSCompositeSourceOver);
    [NSGraphicsContext restoreGraphicsState];

    [NSGraphicsContext saveGraphicsState];
    [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(frame, 1.0f, 1.0f) xRadius:3.0f yRadius:3.0f] setClip];
    [[NSColor whiteColor] setFill];
    NSRectFillUsingOperation(frame, NSCompositeSourceOver);
    [NSGraphicsContext restoreGraphicsState];
}

But as soon as you are done editing it draws over the text, even though the cursor is still there? Any suggestions? I’ve tried drawing the title but it still happens.

Thanks for your help.

Answer:

NSCell Custom Highlight

By calling super drawInteriorWithFrame:inView I was able to stop the weird text disappearing issues.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:17:05+00:00Added an answer on June 13, 2026 at 10:17 pm

    It looks to me like you’ve ended up drawing inside the drawing of your superclass’s (NSTextField‘s) drawRect: implementation. You haven’t called super but it still manages to draw itself. I’m not sure why myself, but some NSControls such as text fields and buttons, when subclassed, will draw themselves regardless of whether or not you call drawRect: on them. For example, if you subclass a plain NSButton, implement drawRect: and don’t call super, it’ll draw the button anyways. Potentially over whatever you drew, which has caused confusion in the past. The easiest solution is to not subclass NSTextField, and see if there’s another class you can subclass (like NSTextFieldCell mentioned in the comment).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a Wordpress site I have created some custom Post
I am working with a UITable View and I am trying to figure out
I have an iOS app working and am trying to clean up some of
I'm working on a custom dojo-widget. Within the widget I am creating some DOM-Nodes
I am creating a custom text box control to have some default formatting and
I have been working on creating a custom allocator as a fun exercise/practice and
I am currently creating my own custom section headers but I have never dont
I am working in WPF and I am creating some userControl which some of
I am creating a process to do some working. But the process is starting
I'm having troubles with creating a simple list (some expandable lists are already working).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.