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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:18:10+00:00 2026-06-06T08:18:10+00:00

I have a view controller based app that contains several views that I display/hide

  • 0

I have a view controller based app that contains several views that I display/hide depending on some logic. I would like to draw a rectangle which will be the size of the UIView in order to give it like a frame/border shape.

I’m having issue drawing a rectangle. I understand that the following code should do it but I’m not sure why this method is not being called or triggered. I also didn’t see the (void)drawRect:(CGRect)rect method generated anywhere so I placed it myself. Not sure what I’m missing here..

- (void)drawRect:(CGRect)rect;
{   
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 0.0, 1.0); // yellow line

    CGContextBeginPath(context);

    CGContextMoveToPoint(context, 50.0, 50.0); //start point
    CGContextAddLineToPoint(context, 250.0, 100.0);
    CGContextAddLineToPoint(context, 250.0, 350.0);
    CGContextAddLineToPoint(context, 50.0, 350.0); // end path

    CGContextClosePath(context); // close path

    CGContextSetLineWidth(context, 8.0); // this is set from now on until you explicitly change it

    CGContextStrokePath(context); // do actual stroking

    CGContextSetRGBFillColor(context, 0.0, 1.0, 0.0, 0.5); // green color, half transparent
    CGContextFillRect(context, CGRectMake(20.0, 250.0, 128.0, 128.0)); // a square at the bottom left-hand corner
}
  • 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-06T08:18:11+00:00Added an answer on June 6, 2026 at 8:18 am

    If all you need to do is add a simple rectangular border, just do the following in your viewWillAppear: for your view controller.

    - (void) viewWillAppear:(BOOL)animated
    {
       //Simple border on the main view
       self.view.layer.borderColor = [UIColor redColor].CGColor;
       self.view.layer.borderWidth = 2;
    
       //Or a simple rectangle to place at x,h within the main view 
       UIView *test = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
       test.backgroundColor = [UIColor redColor];
       [self.view addSubview:test];
    }
    

    Hope this helps!

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

Sidebar

Related Questions

I have a split view controller-based iPad app that uses a Web View to
I have a View controller displaying some information (not table views). I have an
I have a view controller that houses a UIWebView. I want to display an
I have a view based app that works well. (In other words, I'm not
I have a split view-based app that presents a master-detail interface, and uses a
I have a navigation controller-based app in which I would like to temporarily disable
I need some help. I have an app that is based on UITabBarController. It
I created a navigation controller based app. The view that opens up below the
I have a view controller that contains a table view, the items in the
I have a navigation-based app and say my root controller A causes a viewController

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.