我正在尝试通过Xamarin.ios中的代码构建用户界面。该代码运行时没有错误消息,但屏幕只是纯白色的表面。
我尝试将以下代码添加到ViewDidLoad中,并且能够逐行逐步调试该代码,但是没有呈现任何内容。遗失了什么?
public override void ViewDidLoad()
{
base.ViewDidLoad();
UIButton button = new UIButton(UIButtonType.RoundedRect);
button.SetTitle("Hello", UIControlState.Normal);
button.Frame = new CGRect(50, 50, 50, 50);
this.View.AddSubview(button);
View.BackgroundColor = UIColor.Blue;
this.Title = "Scroll view";
view1 = new UIView(new CGRect(100,100,100,100));
view1.BackgroundColor = UIColor.Blue;
View.AddSubview(view1);
var label1 = new UILabel(new CGRect(10, 60, 300, 30));
label1.Text = "Funkar";
label1.BackgroundColor = UIColor.Gray;
view1.Add(label1);
scrollView = new UIScrollView(new CGRect(200, 200, 200, 200));
scrollView.BackgroundColor = UIColor.Red;
View.AddSubview(scrollView);
FinishedLaunching看起来像这样:
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
Window = new UIWindow(UIScreen.MainScreen.Bounds);
viewController = new MyViewController();
navigationController = new UINavigationController();
navigationController.PushViewController(viewController, false);
Window.RootViewController = navigationController;
Window.MakeKeyAndVisible();
return true;
}