

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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.
- Related Questions & Answers
- Change the background color of a button with CSS
- How to make a Button Hover to change the Background Color in Tkinter?
- How to change the background color using jQuery?
- How to animate a change in background color using jQuery on mouseover?
- How to change JFrame background color in Java
- How to change axes background color in Matplotlib?
- Change Background color of a web page using onmouseover property
- How to reset the background color of a Python Tkinter button?
- How to change header background color of a table in Java
- How to change the background color of a Treeview in Tkinter?
- How to change the background color of a tkinter Canvas dynamically?
- How to Change color of Button in Android when Clicked using Kotlin?
- How to change the background color of ListView items on Android using Kotlin?
- How to change JLabel background and foreground color in Java?
- How to change background color of TableView items on iOS?
Advertisements