HOW TO CREATE RECTANGLE ON UIVIEW IN IOS?

sandy taylor

Total Post:46

Points:324
Posted by  sandy taylor
 570  View(s)
Ratings:
Rate this:

I want to create a rectangle shape on our view controller.
I tried it by using this code:

UIView *frameForView = [[UIView alloc] initWithFrame:CGRectMake(0,0,70,70)];
frameForView.backgroundColor=[UIColor greenColor];

I think the above code is correct but I don't understand that how can I fix it on our view controller.
Please tell me what's wrong in my code.

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: How to create rectangle on UIView in iOS?

    It is very simple to set the frame on to the view controller, your code is correct but it needed some other code to fix it.
    Here I am providing complete code:

    UIView *frameForView = [[UIView alloc] initWithFrame:CGRectMake(0,0,70,70)];
    frameForView.backgroundColor=[UIColor greenColor];
    // this code is responsible to add frame into our view controller
    [self.view addSubview:frameForView];

    I hope it is helpful for you.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!