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

  • SEARCH
  • Home
  • 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 6109431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:24:14+00:00 2026-05-23T14:24:14+00:00

Is there a way to draw lines diagonally in NSTableview cell.Can u please post

  • 0

Is there a way to draw lines diagonally in NSTableview cell.Can u please post sample to do this.I am new to the Mac development.Please help me in this issue.

Thanks in advance…….

  • 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-05-23T14:24:14+00:00Added an answer on May 23, 2026 at 2:24 pm

    Yes, easily.

    You need to create a subclass of NSTextFieldCell which is actually the type of cell a NSTableView uses to display text.

    Subclassing an class creates a new version of that class that does all that the original class did plus more.

    This is using Xcode 4. If you are using Xcode 3 let me know.

    In Xcode, create a new file by choosing File > New > New File…

    New File

    In the sheet that pops up choose Objective-C Class and hit Next.

    Objc class

    Make it a subclass of NSTextFieldCell, which is what we will be making a modified copy of. Hit Next.

    subclass

    You can save it as anything you want, but for the purposes of this tutorial, save it as MyDiagonalLinedTextFieldCell. Hit Save.

    saving

    Two new files should pop up.

    files

    Click on the .m file. This is the implementation file that tells what the methods in the class do.
    Its contents should be similar to below:

    //
    //  MyDiagonalLinedTextFieldCell.m
    //  CustomCell
    //
    //  Created by spudwaffle on 7/4/11.
    //  Copyright 2011 __MyCompanyName__. All rights reserved.
    //
    
    #import "MyDiagonalLinedTextFieldCell.h"
    
    @implementation MyDiagonalLinedTextFieldCell
    
    - (id)init
    {
        self = [super init];
        if (self) {
            // Initialization code here.
        }
    
        return self;
    }
    
    @end
    

    Below the init method add a drawInteriorWithFrame: inView: method.
    The application calls the drawInteriorWithFrame: inView: method each time the cell needs to render on screen.

    Your code should now look like this:

    @implementation MyDiagonalLinedTextFieldCell
    
    - (id)init
    {
        self = [super init];
        if (self) {
            // Initialization code here.
        }
    
        return self;
    }
    
    - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
    
    }
    
    @end
    

    The first thing you need to do is just draw a standard NSTextFieldCell.
    This can be done by calling:

    [super drawInteriorWithFrame:cellFrame inView:controlView];
    

    This draws a normal NSTextFieldCell in the exact area the program wants it to.

    Now, we need to draw our custom lines. Let’s put them 5 pixels apart and make them 1 pixel wide.
    This calls for a for loop!

    for (int i = 0; i < cellFrame.size.width/5; i ++) {
    
    }
    

    This makes a int that equals 0,adds to that count every time the loop runs, and stops when i reaches the amount of lines that need to be drawn.

    Next, put in the drawing code to draw the lines.

    for (int i = 0; i < cellFrame.size.width/5; i ++) {
            NSBezierPath *path = [NSBezierPath bezierPath];
            [path moveToPoint:NSMakePoint(i * 5, cellFrame.origin.y)];
            [path lineToPoint:NSMakePoint((i * 5) + 2, cellFrame.origin.y + cellFrame.size.height)];
            [[NSColor grayColor]set];
            [path setLineWidth:1];
            [path stroke];
    }
    

    This:

    1. Creates an NSBezierPath, which is used to draw lines and shapes.
    2. Moves the start of the path to the bottom edge of the cell.
    3. Draws a line to the top edge of the cell.
    4. Sets the drawing color to gray.
    5. Sets the drawing line width to 1.
    6. Draws the line.

    It does this over and over for each line thanks to the for loop.

    Here is the completed MyDiagonalLinedTextFieldCell.m file. You don’t need to worry about the .h one for now.

    #import "MyDiagonalLinedTextFieldCell.h"
    
    @implementation MyDiagonalLinedTextFieldCell
    
    - (id)init
    {
        self = [super init];
        if (self) {
            // Initialization code here.
        }
    
        return self;
    }
    
    - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
        [super drawInteriorWithFrame:cellFrame inView:controlView];
        for (int i = 0; i < cellFrame.size.width/5; i ++) {
            NSBezierPath *path = [NSBezierPath bezierPath];
            [path moveToPoint:NSMakePoint(i * 5, cellFrame.origin.y)];
            [path lineToPoint:NSMakePoint((i * 5) + 2, cellFrame.origin.y + cellFrame.size.height)];
            [[NSColor grayColor]set];
            [path setLineWidth:1];
            [path stroke];
        }
    }
    
    @end
    

    Now, we need to set the cells in the table view to use this class.

    Click on your MainMenu.xib file.
    Click on the cell in a row of your table view until it turns blue.

    blue cell

    Then, hit the button in the right side bar that looks like so:
    button

    Change the Class to MyDiagonalLinedTextFieldCell and hit enter.

    class change

    Now hit run and enjoy the fruits of your labor!

    custom cell window

    Mess with the drawing code until you get the exact kind of lines you want.

    Feel free to contact me with any questions.

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

Sidebar

Related Questions

Is there a way to achieve this (OpenGL 2.1)? If I draw lines like
is there an easy way to not draw this points in my lines? I
Is there a way to draw the lines in such a way that they
Is there any way to draw two lines of text on Android SoftKeyboard without
Is there a way to draw an arc using points in JavaScript?? I need
I was wondering if there is a way to draw an image but give
Is there any simple way how to draw obliquely strike through on TextView? Now
Is there a way to make the parent control draw over the children controls
Is there a way (in R with ggplot or otherwise) to draw frequency and
I wondering if there is a faster (GPU time) way to draw a full-screen

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.