 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change a button background color using Swift?
To change the background color of a button in iOS application we need to access the property ‘ backgroundColor’ of the UIButton. We can do this in two ways, programmatically and using the storyboard.
Method 1 − Using the storyboard editor
Add a button on your storyboard, select it Go to it’s attribute inspector and select 'Background' property to choose the color.
Method 2 − Programmatically changing the background
Create outlet of the button on the View Controller.
In the viewDidLoad() or viewWillLayoutSubview() method add the code to change the background color.
btn.backgroundColor = #colorLiteral(red: 0.4392156899, green: 0.01176470611, blue: 0.1921568662, alpha: 1)
When we run the method one by selecting a color on the attribute inspector, below is the result that’s created.

Advertisements
 