
- iOS Tutorial
- iOS - Home
- iOS - Getting Started
- iOS - Environment Setup
- iOS - Objective-C Basics
- iOS - First iPhone Application
- iOS - Actions and Outlets
- iOS - Delegates
- iOS - UI Elements
- iOS - Accelerometer
- iOS - Universal Applications
- iOS - Camera Management
- iOS - Location Handling
- iOS - SQLite Database
- iOS - Sending Email
- iOS - Audio & Video
- iOS - File Handling
- iOS - Accessing Maps
- iOS - In-App Purchase
- iOS - iAd Integration
- iOS - GameKit
- iOS - Storyboards
- iOS - Auto Layouts
- iOS - Twitter & Facebook
- iOS - Memory Management
- iOS - Application Debugging
- iOS Useful Resources
- iOS - Quick Guide
- iOS - Useful Resources
- iOS - Discussion
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 Articles
- 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 change the background color after clicking the button in JavaScript?
- How to change background color of a canvas circle using Fabric.js ?
- How to animate a change in background color using jQuery on mouseover?
- How to change selection background color of a canvas circle using Fabric.js?
- How to change background color of canvas-type text using Fabric.js?
- How to reset the background color of a Python Tkinter button?
- How to change the color of the radio button using CSS?
- How to change JFrame background color in Java
- How to change axes background color in Matplotlib?
- How to change the background color of UIStackView?
- Change Background color of a web page using onmouseover property
- How to Change color of Button in Android when Clicked using Kotlin?

Advertisements