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

Localizable resources


A localizable resource is content, such as images and sound files, which is specific to a locale. In this recipe, we will learn how to load and display resources based on the user's localization preferences.

Getting ready

Create a new Single View Application in Xamarin Studio and name it LocalizableResourcesApp. Add a label and a UIImageView on the view of LocalizableResourcesAppViewController. Two different images will also be needed, one for each locale. The images of USA and Spain are used in this example.

How to do it...

Perform the following steps:

  1. Add two folders for the English and Spanish locales to the project (en.lproj and es.lproj).

  2. Add one image in each folder. Make sure that the filename for the images is the same within both the folders.

  3. Enter the following code in the LocalizableResourcesAppViewController class:

    public override void ViewWillAppear (bool animated)
    {
      base.ViewWillAppear (animated);
      this.lblLocale.Text = NSLocale.PreferredLanguages[0];
      this...