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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:30:37+00:00 2026-05-24T22:30:37+00:00

I have a simple UIView, in drawRect: I am adding a UIImageView as a

  • 0

I have a simple UIView, in drawRect: I am adding a UIImageView as a subview, then trying to draw a line on top of that subview. But, the line gets draw behind the imageview.

How can I make the drawing context be the subview so I can draw on top of it?

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 10.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0, 0);
CGContextAddCurveToPoint(context,125,150,175,150,200,100);
CGContextAddCurveToPoint(context,225,50,275,75,300,200);
CGContextStrokePath(context);
  • 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-24T22:30:37+00:00Added an answer on May 24, 2026 at 10:30 pm

    Make another custom view, that has the only job of drawing the line. Add it as a subview with the same frame as the ImageView, and call bringSubviewToFront to make sure it’s in front. You might have to set some attributes on your custom view like opaque = NO and set the background color to clear ([UIColor colorWithWhite:0.0 alpha:0.0]).

    By the way, don’t add any subviews in drawRect. drawRect should just draw, not change the view attributes or hierarchy. You should add the ImageView and the custom line drawing view somewhere else, maybe in the init. Like so:

    @implementation MyView
    
    -(id)initWithFrame:(CGRect)frame {
        if ((self = [super initWithFrame:frame])) {
            imageView = ... // however you create your image view
            [self addSubview:imageView];
            lineView = [[MyLineView alloc] initWithFrame:imageView.frame];
            [self addSubview:lineView];
            [self bringSubviewToFront:lineView];
        }
        return self;
    }
    
    ...
    
    @end
    
    @implementation MyLineView
    
    -(void)drawRect:(CGRect)rect {
        // your drawing code
        // remember the coordinate system now has (0, 0) at the top left corner of the
        // image view, so adjust your drawing code accordingly
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple custom UIView (a rectangle) that is implemented with drawRect. The
I have a simple app that just displays a UIImageView. For some reason the
I have a UIView subclass that draws a simple rectangle with this code: -
This is probably a simple question... I have a UIView with a button that
In my project I have a simple UIView with a UIScrollView subview. I am
I currently have 3 simple UIImageViews that animate across a UIView in my app.
I have simple win service, that executes few tasks periodically. How should I pass
I have simple WinForms application where modifying Windows Registry. The problem is that in
I have a little UIView object, CircleColorView.m, that simply creates a view with a
I have a simple UIView *myView which is set as follows myView.image = [UIImage

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.