
- 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
Change Color of Button in iOS when Clicked
Imagine you’re playing a song and as soon as you press the stop button, the color of the button should turn to red. This is one of the many scenario where you might need to change the color of button when it is clicked.
In this tutorial we will see how to change the background color of a button when it is clicked. So let’s get started!
Step 1 − Open Xcode → New Projecr → Single View Application → Let’s name it “ChangeButtonColor”
Step 2 − In the Main.storyboard create one button and name it stop.
Step 3 − Create @IBAction of the button and @IBOutlet of the button and name it btnChangeBgColor and btnBgColor respectively. Here we are using both action and outlet, because on action of the same button we want to change the property of the same.
Step 4 − In the action of the button type the following code.
@IBAction func btnChangeBgColor(_ sender: Any) { self.btnBgColor.backgroundColor = UIColor.red }
Step 5 − Run the code.
- Related Articles
- How to change color of Button in Android when Clicked?
- How to Change color of Button in Android when Clicked using Kotlin?
- How to customise iOS button to set text and color?
- How to change the color of ttk button in Tkinter?
- How to change background color of TableView items on iOS?
- How to change the color of a button when the input field is filled – JavaScript?
- Change the background color of a button with CSS
- Change the color upon hovering over Button in Tkinter
- How do I open phone settings when a button is clicked in Swift?
- Execute a script when a reset button in a form is clicked in HTML?
- How to prevent a dialog from closing when a button is clicked?
- How to put url into a variable when button is clicked - jQuery?
- How do I make a pop-up in Tkinter when a button is clicked?
- How to change the font and color on the UITextView in iOS?
- How to change a button background color using Swift?
