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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:36:46+00:00 2026-05-23T07:36:46+00:00

I want to draw an rectangle and can change the rectangle’s position and size

  • 0

I want to draw an rectangle and can change the rectangle’s position and size realtime.

I have tried following two methods, but the view don’t show the rectangle.

do you have any advice or example?

appreciate your help.

use view frame (it only show the new rectangle when restart the app)

UIView * drawView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 10, 10)];
[self.view addSubview:drawView];
drawView.layer.borderColor = [[UIColor orangeColor] CGColor];
drawView.layer.borderWidth = 2;

drawView.frame = CGRectMake(r.x, r.y, r.width, r.height);

draw in the drawRect

fav = [[FaceAugmentingView alloc] initWithFrame:[imageView frame]];
fav.backgroundColor = [UIColor clearColor];
[self.view addSubview: fav  ];
fav.face = CGRectMake(r.x, r.y, r.width, r.height);
[fav setNeedsDisplay];
  • 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-23T07:36:46+00:00Added an answer on May 23, 2026 at 7:36 am

    I suggest you add a method that reloads the faces based whenever you need to alter it. Declare and array that will help us keep track of all the views we’ve added.

    @interface FacesViewController: UIViewController
    [..]
    @property (nonatomic, retain) NSMutableArray * faceViews;
    
    - (void)reloadFaces;
    [..]
    @end
    

    And then implement reloadFaces something like this –

    - (void)reloadFaces {
        /* remove all current views we've added */
        for ( UIView * aView in self.faceViews ) {
            [aView removeFromSuperview];
        }
        [self.faceViews removeAllObjects];
    
        /* Add news ones */
        int numberOfFaces = [self numberOfFacesInImage];
        for ( int i = 0; i < numberOfFaces; i++ ) {
            CGRect faceFrame = [self frameForFaceAtIndex:i];
    
            UIView * drawView = [[[UIView alloc] initWithFrame:faceFrame] autorelease];
            drawView.layer.borderColor = [[UIColor orangeColor] CGColor];
            drawView.layer.borderWidth = 2;
            drawView.frame = CGRectMake(r.x, r.y, r.width, r.height);
    
            [self.view addSubview:drawView];
            [faceViews addObject:drawView];
        }
    }
    

    I would expect reloadFaces to be called when there is a change of some kind. numberOfFacesInImage and frameForFaceAtIndex: are methods that you will have to implement based on how you get the data. You can also replace them to suit your data model. Don’t forget to initialize faceViews.

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

Sidebar

Related Questions

I want to draw five rectangle bars in Android. I have the regtangles, but
I was a problem with drawing rectangle using mouse. I have solve my problem
I want to draw a shape with square, diamond, and cross shape. The square
I want to draw the number badge as shown in the above image on
I want to draw a moving sine wave with variable frequency and variable amplitude
I have a problem with drawing. I have a frame with one button. Using
today I have a (simple) rendering problem for you. My current project gets datas
What is the best way do draw an strike text with iPhone sdk? I
I want to carry out a linear regression in R for data in a
I'm drawing points on a map with OpenLayers like in this example: http://dev.openlayers.org/examples/draw-feature.html Now

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.