views
Using UIColor to customize app appearance - Javatpoint
UIColor is a subclass of NSObject used to store color and opacity information about an object in the iOS app. The UIColor is declared as shown below.
Colors are the most important aspect to improve our application's appearance. We can use colors to help users to visualize data. Apple provides several ways to select colors in the app. Two of the most used color identification systems are RGB and HSB. However, programmers mostly use RGB (Red-Green-Blue) color system. The RGB contains the combination of red, green, and blue colors, where each color contains a value between 0 and 255. The 255 represents the full color, whereas 0 represents no color.
The UIColor class manages the colors used in the application. It provides a list of class properties that can specify the system-provided colors for UI elements such as labels, text, buttons, and images. We can also create the colors by specifying the hex code or providing different components from other color objects. We can also create a pattern-based color from an object.
The UIColor class provides the following methods to configure the app appearance.
The UIColor contains the following properties.
Apple provides various built-in color shown below. The built-in colors are accessed with the class variables.
The built-in color can be assigned using the following code.
As we have already mentioned that the built-in colors are the class variables, we can use these colors directly from the UIColor class.
The UIColor class provides various initializers which can be used to create custom UIColor. It facilitates us to create our color, which will be in-between the built-in colors.
We can use the UIColor initializer to build a custom color object, as shown below.
Example
Let's create an iOS app to demonstrate how we can use UIColor objects to configure the application's appearance.
We will use UISlider in our app. We can control the red, green, and blue components by changing the values of the slider. The interface builder of the app is shown below.
Let's create the outlets for red, green, and blue sliders. We will also create the action outlet for the sliders, which will be triggered when the value for the sliders will be changed.
Add the following code in ViewController.swift.
Now, run the app on the simulator and see the result as shown below. The background color of the view will be changed as we move the sliders.
SoapUI
RPA
Manual T.
Cucumber
Appium
PostgreSQL
Solr
MongoDB
Gimp
Verilog
Teradata
PhoneGap
Aptitude
Reasoning
Verbal A.
Interview
Company
AI
AWS
Selenium
Cloud
Hadoop
ReactJS
D. Science
Angular 7
Blockchain
Git
ML
DevOps
DBMS
DS
DAA
OS
C. Network
Compiler D.
COA
D. Math.
E. Hacking
C. Graphics
Software E.
Web Tech.
Cyber Sec.
Automata
C
C++
Java
.Net
Python
Programs
Control S.
Data Mining
Hindi100
Lyricsia
Website Development
Android Development
Website Designing
Digital Marketing
Summer Training
Industrial Training
College Campus Training
Address: G-13, 2nd Floor, Sec-3
Noida, UP, 201301, India
Contact No: 0120-4256464, 9990449935
© Copyright 2011-2018 www.javatpoint.com. All rights reserved. Developed by JavaTpoint.