---
title: "How to use Gradient color in UIView in iOS?"  
description: "How to use Gradient color in UIView in iOS?"  
author: "Tarun Kumar"  
published: 2015-12-30  
updated: 2015-12-30  
canonical: https://www.mindstick.com/forum/33811/how-to-use-gradient-color-in-uiview-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# How to use Gradient color in UIView in iOS?

I want to create [gradient](https://www.mindstick.com/blog/161/gradient-background-in-c-sharp) [color](https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp) and want to use it into our UIView. Can [anyone tell me](https://www.mindstick.com/interview/23033/can-anyone-tell-me-about-hadoop-toolbox) how can I generate a [view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view) with gradient color [background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp) in runtime.If is there any way to do that then please provide [me the code](https://www.mindstick.com/forum/156831/can-you-tell-me-the-code-to-write-a-c-sharp-program) also.

## Replies

### Reply by Anonymous User

The [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) I am providing here is already running in my own application, so I hope my code is helpful for you:

```
CAGradientLayer *gradient = [CAGradientLayer layer];gradient.frame = selectedView.bounds;gradient.colors = [NSArray arrayWithObjects:                          (id)[[UIColor blackColor] CGColor],                          (id)[[UIColor greenColor] CGColor],                          (id)[[UIColor redColor] CGColor], nil];
```

our gradient color is created, now we assign it in our view layer, like this:

```
[view.layer insertSublayer:gradient atIndex:0];
```


---

Original Source: https://www.mindstick.com/forum/33811/how-to-use-gradient-color-in-uiview-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
