---
title: "How to create rectangle on UIView in iOS?"  
description: "How to create rectangle on UIView in iOS?"  
author: "Anonymous User"  
published: 2016-01-20  
updated: 2016-01-20  
canonical: https://www.mindstick.com/forum/33904/how-to-create-rectangle-on-uiview-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# How to create rectangle on UIView in iOS?

I want to create a [rectangle shape](https://www.mindstick.com/forum/33905/how-to-crop-image-in-rectangle-shape-in-ios) on our [view controller](https://www.mindstick.com/forum/33709/how-to-use-table-view-controller-with-small-sized-in-ios).\
I tried it by using this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
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](https://yourviews.mindstick.com/view/80763/donald-trump-ki-jeet-fix-hai) it on our view controller.\
[Please tell me](https://www.mindstick.com/forum/33900/please-tell-me-what-are-the-technique-to-content-optimization) what's [wrong](https://answers.mindstick.com/qa/48468/who-wrote-the-the-wrong-enemy-america-in-afghanistan-2001-2014-and-when) in my code.

## Replies

### Reply by Tarun Kumar

It is very simple to set the frame on to the [view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-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.


---

Original Source: https://www.mindstick.com/forum/33904/how-to-create-rectangle-on-uiview-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
