Found 517 Articles for Swift

Explain what floating point numbers are and what types of floating points are available in Swift

Nitin Aggarwal
Updated on 28-Feb-2023 12:28:04

1K+ Views

A floating point number represents a value with a decimal point. In Swift, there are two types of floating point numbers i.e. Float and Double. They both are very similar with some unique use cases. Float They represent 32-bit decimal numbers in the Swift language. When you want to store floating point numbers with small precision, Floats are the best use case. Float has a precision of 6 to 9 decimal digits in floating point numbers which represent the 32-bit space in memory. The range of values that can be represented by a Float is approximately -3.4 x 10^38 to ... Read More

Explain some common features of Protocol & Superclass in Swift

Nitin Aggarwal
Updated on 28-Feb-2023 12:25:52

206 Views

In Swift, there are two different concepts i.e. protocols and superclasses are used to build the application by writing reusable and flexible code. They both are different concepts but somehow they have some common features. You can define the protocol with methods and properties to achieve any particular feature. In the same way, you can create a class with methods and properties to hold some information. Swift provides flexibility in that class, structure, and enums can conform to a protocol. A superclass is also a class type. It can be inherited from other classes in a similar way. In this ... Read More

How to create a button programmatically?

Nitin Aggarwal
Updated on 28-Feb-2023 12:21:47

1K+ Views

In this article, you will learn about how to create a button prograticamtilly in the Swift language. There are different ways to create a button object programmatically in iOS. Let's explore some of them with an example. We will see the following ways to create a button − Step 1 − In this step, we will create a button object and customize it later when required. Step 2 − In this step, we will create a button object using a lazy keyword. Step 3 − In this step, we will create a button object and set the frame later. ... Read More

How can I make a button have a rounded border in Swift?

Nitin Aggarwal
Updated on 28-Feb-2023 12:20:20

5K+ Views

In Swift, you can use the layer property of a UIButton to set the corner radius of its border. You can use the layer (CALayer) property to apply the border width and color to the button. Also, the same property provides access to the cornerRadius property to make the button rounded. We will use the following steps to make a button rounded with a border Step 1 − In this step, create a button object with basic customization. Step 2 − In this step, add a border and corner radius to the button. Step 3 − In this step, make ... Read More

Changing the text of UIButton programmatically in Swift

Nitin Aggarwal
Updated on 28-Feb-2023 12:18:50

6K+ Views

To change the text of a UIButton in Swift, you can use the setTitle() method of the button. This method takes an argument to set the button title for a particular state. Generally, we used the normal button state. We will change the text of the button programmatically by following the below steps − Step 1 − In this step, we will create two buttons (login and T&C) and add basic customization. Step 2 − In this step, we will change the text of the login button. Step 3 − In this step, we will change the text of the ... Read More

Programmatically go back to the previous ViewController in Swift

Nitin Aggarwal
Updated on 28-Feb-2023 12:15:25

4K+ Views

This article explains how to go back from a view controller programmatically using Swift language. You will see an example of using the popViewController method to go back to the previous controller. What is ViewController in Swift? In Swift, a UIViewController manages the interaction between the user interface and the logic data. It is responsible for handling user interactions with the user interface. The class is part of the UIKit framework and provides some functions and properties along with a life cycle. This class is the most common class used in iOS development. To go back to a previous view ... Read More

How to hide the keyboard in Swift by pressing the return key?

Nitin Aggarwal
Updated on 28-Feb-2023 12:14:04

2K+ Views

In this article, you will learn about how you can hide the keyboard while editing text in the UITextField. In this example, you will hide the keyboard by pressing the return button on the keyboard. In the Swift language, UITextField class provides us with some delegate methods. They called on different actions or events. We will implement one of the delegate methods to hide the keyboard. Also, you will see how to change the return type if required. In this example, we will hide the keyboard in UITextField to enter an email address by following the below steps − ... Read More

How to change the font of UIButton with Swift?

Nitin Aggarwal
Updated on 28-Feb-2023 12:12:57

8K+ Views

In Swift, this is very easy to change the font of a button. You can use the titleLabel property of the button which is of type UILabel class. This property provides another property called font to apply the desired font. Let’s see some examples of changing the font. We will follow the below steps to change the font of a button − Step 1 − Initially, we will do the basic setup with button creation and customization. Step 2 − In this step, we will change the system font with size and weight. Step 3 − In this ... Read More

Swift Program to print the right diagonal matrix

Ankita Saini
Updated on 16-Feb-2023 16:45:03

498 Views

A matrix is an arrangement of numbers in rows and columns. Matrix can be of various type like square matrix, horizontal matrix, vertical matrix etc. So here we print the right diagonal of square matrix. Square matrix is a matrix in which the number of rows and columns are same. For example 3x3, 5x5, 7x7, etc. In this article, we will learn how to write a swift program to print the right diagonal matrix. Algorithm Step 1 − Create a function. Step 2 − Run for-in loop to iterate through each element of the matrix. Step 3 − Check for ... Read More

Swift Program to print the left diagonal matrix

Ankita Saini
Updated on 16-Feb-2023 16:44:06

405 Views

In this article, we will learn how to write a swift program to print the left diagonal matrix. A matrix is an arrangement of numbers in rows and columns. Matrix can be of various type like square matrix, horizontal matrix, vertical matrix etc. So here we print the left diagonal of square matrix. Square matrix is a matrix in which the number of rows and columns are same. For example 3x3, 5x5, 7x7, etc. Algorithm Step 1 − Create a function. Step 2 − Run for-in loop to iterate through each element of the matrix. Step 3 − Check ... Read More

Advertisements