How to set background color of a View in iOS App?


Views are the fundamental building blocks of your app's user interface, and the  UIView class defines the behaviors that are common to all views. A view object renders content within its bounds rectangle and handles any interactions with that content. The  UIView class is a concrete class that you can instantiate and use to display a fixed background color.

It is very important to have complete understanding of UIView as they are the main object user sees.

Here we will be seeing how to change the background color of view programmatically and via storyboard.

First let us see using storyboard, Open Main.storyboard and add one view to the View Controller.

On the right pane you can see the property, and from there update the background color to color you want your view to be as show below.

Now let us see how we can change the color programmatically. Use the below code and change the value to desired colour.

self.view.backgroundColor = UIColor.cyan

raja
Published on 16-Jul-2019 15:01:11
Advertisements