Tutorial for making Scroll View ui on iOS
Learn how to scroll through iOS in Swift with an example; This xcode example also teaches you how to use scrollview uicontrol on iOS to display content that is larger than the visible range.
Scroll View UI on iOS
In iOS, Scroll View is used to display content that is larger than the display range; For example, displaying multi-page content of documents or multiple images is used in the application. When we look at the scroll view, it means the existing content; More than the visible area of the page.
By default, the survey view; Does not have a unique appearance to offer; But whenever the app is open; Tap or touch the screen; A scrolling view appears. Show additional content as shown below.
We can now use Scroll View in our iOS apps by adding a UIScrollView class reference.
Now with an example, we can see how we can use the UI navigation view in our iOS apps.
Create a scrolling application 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, making a scroll view on iOS, we have one of 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: “iPhone Articles”
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 phrases 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 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 use the ViewController.swift file in your project, which looks similar to the one below.
Add iOS UI controls to display in Xcode
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 Scroll View in the Object Library in the Filter box, then drag and drop Scroll View into ViewController in Main.storyboard, similar to what you see below.
Now drag the button from the objects library to the ViewController file and click on the button and change the name to “Hello Scroll” similar to what you see below.
Relate iOS UI controls to coding in Swift
We now connect the controls and the ViewController.Swift code. To do this, click on the Assistant button, which is located in the lower right corner of the Xcode toolbar (the two circles are intertwined).
To map the controls, hold down the Ctrl key on the keyboard and drag the Scroll View from the interface and drop it into the ViewController.swift file as shown below.
When we added the controls to the ViewController.swift file; Then we have to write custom code to resize the content; Show navigation bar. When we have written all the required functions; The code for the ViewController.swift file will be similar to the following:
Import UIKit
Class ViewController: UIViewController {
@IBoutlet weak var scollView: UIScrollView!
override func viewDidLoad () {
super.viewDidLoad ()
scrollView.contentSize.height = 1000
}
Override func didReceiveMemoryWarning () {
Super.didReceiveMemoryWarning ()
// Dispose of any resouces that can be recreated.
}
}
Now run the program and check the output of the application. To run the program, select the required emulator (here we have selected iPhone Six S Plus) and click on the Play button; Which is similar to the one below in the upper left corner of the Xcode toolbar.
IOS survey view app output in Scroll View ui
Below you can see the result of running the scroll view application. If you are careful; You will see the page browser because in coding, we set the content size to 1000.
This way we can use the ui page browser view in our iOS apps to get content that is larger than the page display limits; To be shown.