Create simple User-Interface via code using Xamarin.iOS

xamarin, xamarin.ios

Solution

Yes, you can create UI via code. Using XCode's designer is entirely optional.

UIButton btn = new UIButton (UIButtonType.RoundedRect);
        
btn.SetTitle ("Hello", UIControlState.Normal);

btn.Frame = new RectangleF (50, 50, 50, 50);
    
    

btn.TouchDown += delegate {
    
      UIAlertView alert = new UIAlertView("Hello", "Hello, Xamarin!", null, "OK");

      alert.Show();

  };


this.View.AddSubview (btn);
    

For data entry UI, you may also want to consider using MonoTouch.Dialog.

Problem

I need to create a simple login form (Username / Password) for a demo using Xamarin.iOS, but I would prefer not having to dive into XCode for this at this moment. Maybe something similar to what you can do in other .NET technologies: ``` var panel = new Panel(); panel.Controls.Add(new Label("Username")); panel.Controls.Add(new TextBox("Password")); ``` Is there a way to create simple interfaces in Xamarin for iOS programatically? Or it is required to design the interfaces using XCode only?

Original source