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 585077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:57:55+00:00 2026-05-13T14:57:55+00:00

I am still struggling with drawing a line with CGContext. I have actually go

  • 0

I am still struggling with drawing a line with CGContext. I have actually go to line to draw, but now I need the background of the Rect to be transparent so the existing background shows thru. Here’s my test code:

(void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextSetAlpha(context,0.0);
    CGContextFillRect(context, rect);

    CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
    CGContextSetLineWidth(context, 5.0);
    CGContextMoveToPoint(context, 100.0,0.0);
    CGContextAddLineToPoint(context,100.0, 100.0);
    CGContextStrokePath(context);
}

Any ideas?

  • 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-13T14:57:56+00:00Added an answer on May 13, 2026 at 2:57 pm

    After UIGraphicsGetCurrentContext() call CGContextClearRect(context,rect)

    Edit:
    Alright, got it.

    Your custom view with the line should have the following:

    - (id)initWithFrame:(CGRect)frame {
        if (self = [super initWithFrame:frame]) {
            [self setBackgroundColor:[UIColor clearColor]];
        }
        return self;
    }
    
    - (void)drawRect:(CGRect)rect {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextClearRect(context, rect);
        CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
        CGContextSetLineWidth(context, 5.0);
        CGContextMoveToPoint(context, 100.0,0.0);
        CGContextAddLineToPoint(context,100.0, 100.0);
        CGContextStrokePath(context);
    }
    

    My test used this as a very basic UIViewController:

    - (void)viewDidLoad {
        [super viewDidLoad];
        UIImageView *v = [[UIImageView alloc] initWithFrame:self.view.bounds];
        [v setBackgroundColor:[UIColor redColor]];
        [self.view addSubview:v];
        TopView *t = [[TopView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:t];
        [v release];
        [t release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still struggling with understanding classes, I am not certain but I have
I have check many sample codes but still struggling to make mine work properly.
A brief background: I'm working on a web-based drawing application and need to draw
I have searched and found loads of examples but am still struggling to make
I posted a question about this last night but am still struggling. I need
I have been struggling with this yesterday whole day, and still couldnt figure it
While I'm still struggling to find a solution for this question, i have another
I'm still struggling with this concept. I have two different Person objects, very simply:
still struggling with regex :) i have this code: $link = '/\bhttp:\/\/.+\..+[\/\w]?\b/i'; $match =
I've tried to install Matplot lib but I'm still struggling to get past errors.

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.