question

DubiSharon-8646 avatar image
0 Votes"
DubiSharon-8646 asked RobCaplan edited

How to fill safeareas for Xamarin iOS project only with code

Hello,
I have an iOS Project (code only, no storyboard or forms)
I would like to have a custom background image to fill the whole screen including the safe areas in my view controller.
How can this be done using only code within the VC ?
Thank you
Dubi

dotnet-xamarin
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Do you want to make the image to fill the whole screen with background C# code in the safe areas? without any other xml layout.

0 Votes 0 ·

yes! Is it possible ?

0 Votes 0 ·

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

Yes, you can add following code in your VC.

[Register("UIViewController1")]
    public class UIViewController1 : UIViewController
    {
        public UIViewController1()
        {
        }

        public override void DidReceiveMemoryWarning()
        {
            // Releases the view if it doesn't have a superview.
            base.DidReceiveMemoryWarning();

            // Release any cached data, images, etc that aren't in use.
        }

        public override void ViewDidLoad()
        {
           // View = new UniversalView();

            base.ViewDidLoad();

            // Perform any additional setup after loading the view
          
            UIImageView textView = new UIImageView();
            textView.Image = UIImage.FromBundle("test");
            textView.Frame = UIScreen.MainScreen.Bounds;
            textView.InsetsLayoutMarginsFromSafeArea = false;
            this.View.Add(textView);
        }
    }


I add my test.png image to the Asset

85246-image.png

Here is my running screenshot.

85227-image.png

Best Regards,

Leon Lu



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (16.2 KiB)
image.png (171.7 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@DubiSharon-8646 Did you test above code in your VC, is that your needs? If not, please share more details about your design.

0 Votes 0 ·