TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to SWIFT

Swift UIImageView Example

UIImageView. We see a palm tree, a cat, a snow-covered mountain. In our visual world images are important. With an Image View we display them in iPhone programs.
Get started. Please create a Single View Application in Xcode and open the object library. Drag an Image View to the iPhone screen.
Add Image View. The control will appear as a blue rectangle in Xcode. Now press control and drag the control to your ViewController.swift file. This adds an outlet.
Add outlet. Please name the UIImageView something nice like "simpleImageView." Now we can reference the Image View with Swift code.

Note: For simple requirements we can just use images added directly in Xcode with the Assets.xcassets file.

Example ViewController, UIImageView: Swift // // ViewController.swift // ExampleTime8 // // ... // import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } @IBOutlet weak var simpleImageView: UIImageView! override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
Add to Assets.xcassets. Click on the Assets.xcassets file in your Single View Application to open the Assets library. In this library we store static images for use in our iPhone app.

Next: Create a new Image asset. Then drag an image from the Finder to a square in the assets.

Image: You can provide a custom name for the image. I named the image I chose "Pastels" this is the key we access it from later.

Set Image. Go back to the Image View we added and click on it. Open the Attributes pane on the right side and set the Image property.

Pastels: You will want to link the image to the name you chose in the Assets.xcassets file (in my example I used "Pastels").

Run simulator. Now run the simulator by clicking the right arrow in Xcode to built and test. The image you added should appear in the iPhone screen.
With UIImageView and UIImage, we add images to our iOS apps. Built-in libraries handle images like JPGs and PNGs. Usually no custom code is needed.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf