Learn how to view iOS UI text in plain language
We will learn about textview ui in iOS by giving an example; Also using this example in xcode we can learn how to use the ui text viewing control on iOS and display a multi-line text.
Display UI text on iOS
IOS ui text display control is used to manage multi-line text or large text. IOS Text Display can automatically display texts whose content is larger than the screen; Scrolls and allows the user to style text; Change colors, fonts and ؛; Either underline the texts or bold them and so on.
If we click inside textview; A keyboard is automatically displayed so you can type content into a text display.
We add the UITextView class reference to our applications; We can use Text View in iOS apps.
Here’s an example of how to use the text display in iOS apps.
Create an iOS text display app in Swift
To create a new project in Xcode on iOS, open Xcode from the application folder list. After opening Xcode, the welcome window will open as shown below. In the Welcome window, click on the second option, “Create a new Xcode Project”; Click (create a new Xcode Project) or select the File New Project path.
After selecting “Create a new Xcode project”, a new window will open in which we must select our template.
The new Xcode window includes several built-in application templates to implement the usual type of iOS apps, such as page-based apps, tab-based apps, games, spreadsheet apps, and more. These templates have a preset interface and source code files. .
For example, the text display on iOS, we have the most basic pattern of the program, which is “demo only”; We will use. To select this item, go to the iOS section on the left, select the application from the select section, and in the main part of the window that opens, select “single view application” and click on the next button, as shown below. .
After clicking Next, we will see a window like the one below, in this case we have to mention the project name and other details for our program.
Product name: “UITextView” (iOS image view)
The name we enter in the Product Name section is used for the project and application.
Organization name: “Tutlane”
You can enter the name of the organization or your name in this field; Of course you can leave that section blank.
Organization Identifier): “com.developersocociety)”
If you do not have an enterprise ID, enter com.example.
Bundle Identifier: This section is automatically generated based on the terms we entered in the product name and organization ID.
Language: “Swift”
Select the language type “Swift” because we want to develop applications using swift.
Universal (devices): “Universal”
Select the Devices option as Universal This means that this app is for all Apple devices; If you need to run the app for iPad only, you can select the iPad option to restrict your app to running only on iPad devices.
Use core Data: Not selected
This option is used for database operations. Select this option if you are doing any database-related operations in your application, otherwise do not select this option.
Include Unit Test: Not selected
If you need unit tests for your application, select this option otherwise leave it unselected.
Includes UI tests: not selected
Select this option if you need UI tests for your application, otherwise do not select it.
After completing the options, click the Next button as shown below.
When we click the Next button; A new window will open in which you must use the location where you want the new project to be saved; Let’s choose. Once you have selected the new project storage location; As shown below; Click the Create button.
After clicking the Create button, Xcode opens and creates a new project. In our project, Main.storyboard and ViewController.swift are the main files used to design the user interface and maintain the source code.
Main.storyboard – which is the visual interface editor and this file is used to design the application user interface.
ViewController.swift – which contains the source code of our application and we use this file to write any code related to our application.
Now select the Main.storyboard file in the project, until Xcode opens the visual interface editor as shown below.
Now open the ViewController.Swift file in your project, which looks like the following figure.
Add iOS UI controls to the screen in Swift
We are now adding controls to our application for that library of available objects. The object library appears at the bottom right of Xcode. If you did not find the object library, as shown below; Click the button that is the third button in the library selection bar on the left. (On the other hand, you can select the View Utilities Show Object Library path).
As we have suggested; Our interface is the Main.storyboard file, so open the Main.storyboard file. Now look for TextView (Text Viewer) in the Object Library in the Filter box, then drag Text View into ViewController in the Main.storyboard; Likewise similar to the following; We need to add one-button and one-button controls to ViewController.
Now like what you see below; Change the TextView text to Welcome To tutlane.com.
Linking iOS UI controls to Swift language coding
We now connect the controls to the ViewController.Swift coding; To do this, click on the Assistant button, which is located in the lower right corner of the Xcode toolbar.
To map the controls, hold down the Ctrl key on the keyboard and drag the text display, button and label from the interface and drop the following into the ViewController.swift file.
Once we have added the controls to ViewController.swift, we then enter the custom code to receive the text in the text viewer and display it in the label when the button is clicked; We write.
When we write all the functions, the code of the ViewController.swift file should look like the following:
import UIKit
class ViewController: UIViewController, UITextViewDelegate {
@IBOutlet weak var labeltext: UILabel!
@IBOutlet var my TextView: UITextView!
@IBAction func doneButAction (sender: UIButton) {
self.myTextView.resignFirstResponder ()
labeltext.text = myTextView.text
}
Override func viewDidLoad () {
super.viewDidLoad ()
self.myTextView.delegate = self
}
Override func didRecieveMemoryWarning () {
Super.didRecieveMemoryWarning ()
// Dispose of any resources that can be recreated.
Now run the program and check its output. To run the program; Select the required emulator (in this section we have selected iPhone Six S Plus) and click the Play button; Which is similar to the following figure; At the top left is the Xcode toolbar.
IOS text display app output in Swift language
Below you can see the iOS text display app. Now if you click the “Done” button; The text display text is displayed in the same label control as below.
This shows how we can use the UI text display in iOS apps. To be able to manage multi-line texts or large texts based on our needs.