id | title | brief | sdk | |||||
---|---|---|---|---|---|---|---|---|
BDC026CA-1810-E853-419B-7B23AF94EE83 |
Load an Image |
This recipe shows how to load and display an image. |
|
To display an image from code:
-
Edit
Assets.xcassets
file that is automatically added to the project, right-click and select New Image Set. -
Double-click the new image set Name and change it to
MonkeySFO
. -
Click on 1x under the Universal section and select an image to display from the hard drive.
-
Create a
UIImageView
and add the image usingUIImage.FromBundle
:var imageView = new UIImageView (UIImage.FromBundle("MonkeySFO")); imageView.Frame = new CoreGraphics.CGRect (10,10,imageView.Image.CGImage.Width, imageView.Image.CGImage.Height); View.AddSubview(imageView);
Optionally, to display an image in an Image View added to a Storyboard:
-
Edit
Assets.xcassets
file that is automatically added to the project, right-click and select New Image Set. -
Double-click the new image set Name and change it to
MonkeySFO
. -
Click on 1x under the Universal section and select an image to display from the hard drive.
-
In the iOS Designer, drag an Image View onto a View and position and size it as desired.
-
In the Properties Explorer, under Identity set the Name to
imageView
. -
Also in the Properties Explorer, under Image View use the Image dropdown to select
MonkeySFO
. -
In code, the image can optionally be set or changed using the following:
imageView.Image = UIImage.FromBundle("MonkeySFO");