Set background image in UIViewController (MonoTouch)
16,000
Solution 1
try setting the BackgroundColor of your View
myview.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("myimage.png"));
Solution 2
I voted up for the other answers, however today IPhone has different sizes and the correct way to load the image is using UIImage.FromBundle
method:
Here is the assert catalog in the project:
To manage the images:
public override void ViewDidLoad()
{
base.ViewDidLoad();
// replace "name" with the desired name in the asset catalog
this.View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromBundle("name"));
}
Solution 3
Try adding something like the following to your MyViewNameViewController.cs:
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("splash.png"));
}
Author by
Brian David Berman
Updated on July 18, 2022Comments
-
Brian David Berman almost 2 years
I have a screen called HomeScreen which implements UIViewController. I wish to use a background image for this screen. Is there an event that I can override to set this background image in the HomeScreen.cs file?
-
nhenrique about 9 yearsis there any way to make the image scale to the view size and still using it as a background color?
-
Elliot Blackburn over 8 years@nhenrique I am wondering this as well, did you find a solution?
-
Old Fox over 6 years@nhenrique I've added a new answer for your question
-
Old Fox over 6 years@ElliotBlackburn I've added a new answer to solve the different sizes IPhone problem
-
Elliot Blackburn over 6 years@OldFox wow this is old, thanks for updating it. Hopefully it'll help someone else in the future. I don't even use Xamarin anymore haha