- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to load and display an image on iOS App using Swift?
To load and display an image in iOS app we’ll first need to get an image.
Then we’ll drag that image to our project and select copy if required option and our application target.
Let’s see the rest with help of an example.
Now, we’ll create an UIImageView and assign the image to its image property, for that we’ll create a function.
func addImage(imageName img: String) { let imageView = UIImageView() imageView.frame = self.view.frame imageView.contentMode = .scaleAspectFit if let newImage = UIImage(named: img) { imageView.image = newImage } self.view.addSubview(imageView) }
Now, we’ll call this code in our viewDidLoad or any other place where we need.
override func viewDidLoad() { super.viewDidLoad() self.addImage(imageName: "1.png") }
When we run the above code on our application it produces the following result.
- Related Articles
- How to display an image with rounded corners on iOS App using Swift?
- How do I load an image by URL on iOS device using Swift?
- How to load and display an image in ImageView on Android App?
- How to rotate an image in imageview by an angle on iOS App using Swift?
- How to make an HTTP request on iOS App using Swift?
- How to make an HTTP POST request on iOS App using Swift?
- How to create a WebView in an iOS App using Swift?
- How to create a Custom Dialog box on iOS App using Swift?
- How to hide the status bar in a iOS App using Swift?
- How to load an image and show the image using Keras?
- How to integrate a facebook login in swift for iOS App?
- How to send an attachment in email using Swift(ios)?
- How to create scrollable TextView on iOS App?
- How to Apply Gradient to the background view of the iOS Swift App?
- How do I load an Image by URL using Picasso Library on Kotlin?

Advertisements