In this recipe, we will learn how to use the UIImageView
class to display images on screen.
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
.
The following are the steps for this recipe:
Open the
ImageViewerAppViewController.xib
file in Interface Builder.Add a
UIImageView
object on its view. Connect theUIImageView
object with an outlet namedimageDisplay
.Save the document.
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"); }
Right-click on the project in the Solution pad and navigate to Add | Add Files…. Select the image...