- 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
How to align views at the bottom of the screen in iOS
The recommended way and the modern way is to do using constraint. We will be using constraint to align the views at the bottom of the screen.
Step 1: Open Xcode → New Projecr → Single View Application → Let’s name it “ViewAlignment”
I’ll be using UIView, but you can use any UI component following the same steps.
Step 2: Open Main.storyboard change the background color of ViewController (this we are doing for better understanding) and add UIView.
Step 3: Add Constraints − Click on UIView → Add new constraints.
While giving constraints we need to keep in mind 4 parameters, Xaxis, Yaxis, Height and Width, we should make sure we are providing all the four parameters. If either of one is not giving or left untreated an application’s UI may behave abnormally and may crash too. In our case we will align the UIView with bottom, leading and trailing spaces 0 points, If you wish to keep some spaces aside or below you can give 5 or 10 points. In our case we will be giving leading spaces 0 points, trailing spaces 0 points, bottom space 0 point and height 100 points.
Step 4: Change the color of UIView to cyan and your view should finally look like this.
Step 5: After aligning the UIView using Constraints or Auto layout your application should be able to run in any size of screen and in both the orientation.
We will run our application in iPhone 8 and iPad Pro (9.7inch) in both the orientation.
- Related Articles
- How to align views at the bottom of the screen in Android?
- How to remove button bar at the bottom screen?
- How to prevent the screen from sleeping in iOS?
- Align HTML5 SVG to the center of the screen
- How to Align the modal content box to the center of any screen?
- How to lock Screen Orientation programmatically in iOS?
- How to change screen brightness programmatically in iOS?
- Align the flex items in the bottom of the container in CSS
- How to add a border to the top and bottom of an iOS View?
- How to put the title at the bottom of a figure in Matplotlib?
- How to remove whitespaces at the bottom of a Matplotlib graph?
- Align flex items in the center on different screen sizes in Bootstrap
- Align flex items in the end on different screen sizes in Bootstrap
- Align flex items in the start on different screen sizes in Bootstrap
- How to set the chart title at the bottom using ggplot2 in R?