Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Displaying images


In this recipe, we will learn how to use the UIImageView class to display images on screen.

Getting ready

In this recipe, we will see how to bundle and display images in a project. An image file will be needed for display. The image file used here is named Toroni.jpg. Create a new iPhone Single View Application project in Xamarin Studio and name it ImageViewerApp.

How to do it...

The following are the steps for this recipe:

  1. Open the ImageViewerAppViewController.xib file in Interface Builder.

  2. Add a UIImageView object on its view. Connect the UIImageView object with an outlet named imageDisplay.

  3. Save the document.

  4. Back in Xamarin Studio, in the ImageViewerAppViewController class, enter the following code:

    public override ViewDidLoad()
    {
      base.ViewDidLoad();
      this.imageDisplay.ContentMode = UIViewContentMode.ScaleAspectFit;
      this.imageDisplay.Image = UIImage.FromFile("Toroni.jpg");
    }
  5. Right-click on the project in the Solution pad and navigate to Add | Add Files…. Select the image...