maandag 28 december 2009

Using images with MonoTouch

When you want to use images in the Interface Builder and you are programming with XCode, all the images you added to your project in XCode, will be available to you in the Interface Builder under Library. Now, of you are using MonoDevelop and MonoTouch, images used in these kinds of projects will not be available in the Interface Builder.

In this short article I will show you how you still can use images but do it partially by code.

1. Add an UIImageView to your design
Open your main window and drag an UIImageView on it. Create on outlet for it and connect the outlet with this control.

2. Add an image to your project
Add an image to your project but make sure to, at the bottom, override the 'Default Build Action'. Change it to 'content'.

3. Put this image into the image view
Use this code to show the image:


UIImage spLogo = UIImage.FromFile(@"Images/spLogo.jpg");
imgMainLogo.Image = spLogo;

where 'imgMainLogo' is my outlet. Also make sure you use the correct relative path to the image itself. I created a folder 'images' and put my picture in there.

Geen opmerkingen:

Een reactie posten