can not set background color in .net ios?

mc 4,086 Reputation points
2024-06-26T04:57:45.58+00:00

I created .net ios (not xamarin.ios and MAUI).

Window = new UIWindow(frame: UIScreen.MainScreen.Bounds);
var rootView = new MainController();
Window.RootViewController = rootView;
Window.MakeKeyAndVisible();

in MainController

View.BackgroundColor = UIColor.SystemMint;

but the color is:

User's image

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,183 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 38,756 Reputation points Microsoft Vendor
    2024-06-26T08:34:14.6633333+00:00

    Hello,

    After testing, setting the BackgroundColor in both parts of the following code works as expected.

    public class AppDelegate : UIApplicationDelegate
    {
        public override UIWindow? Window
        {
            get;
            set;
        }
     
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // create a new window instance based on the screen size
            Window = new UIWindow(UIScreen.MainScreen.Bounds);
            var rootView = new MainViewController();
    		// Part 1
            rootView.View.BackgroundColor = UIColor.SystemMint;
            Window.RootViewController = rootView;
            Window.MakeKeyAndVisible();
     
            
     
            return true;
        }
    }
    public class MainViewController : UIViewController
    {
        public override void ViewDidLoad()
        {
            View = new UIView
            {
     
            };
     
            //Or Part 2
            View.BackgroundColor = UIColor.SystemMint;
            base.ViewDidLoad();
     
            // Perform any additional setup after loading the view
        }
    }
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


0 additional answers

Sort by: Most helpful