Home > DeveloperSection > Forums > How to create rectangle on UIView in iOS?
sandy taylor
sandy taylor

Total Post:46

Points:324
Posted on    January-20-2016 10:32 PM

 iPhone iPhone  Ios  Objective C 
Ratings:


 1 Reply(s)
 249  View(s)
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.



Tarun Kumar

Total Post:210

Points:1614
Supported
Posted on    January-20-2016 11:05 PM

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.


Don't want to miss updates? Please click the below button!

Follow MindStick