Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create simple User-Interface via code using Xamarin.iOS

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?

like image 250
Meryovi Avatar asked Jul 22 '13 18:07

Meryovi


People also ask

Can Xamarin be used for iOS?

Xamarin. iOS allows developers to create native iOS applications using the same UI controls that are available in Objective-C and Xcode, except with the flexibility and elegance of a modern language (C#), the power of the .

Can I build iOS app on Windows Xamarin?

To build Xamarin. iOS apps with Visual Studio 2019 or Visual Studio 2022 on Windows, you will need: A Windows machine with Visual Studio 2019 or Visual Studio 2022 installed. This can be a physical or a virtual machine.

Can you build iOS apps with C#?

You can build native apps for Android, iOS, and Windows by using C# or F# (Visual Basic isn't supported at this time). To get started, install Visual Studio, select the Mobile Development with . NET option in the installer.

What are the requirements for building Xamarin iOS?

Check your operating system version and follow the instructions for the Xamarin installer. Xcode 10 requires macOS High Sierra (10.13) or newer. The iOS 12 SDK ships with Xcode 10. You can still target older Android versions while using the latest SDK, or you can build against older versions of the SDK if required.


2 Answers

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.

like image 108
Jason Avatar answered Nov 06 '22 08:11

Jason


Perhaps a little late to the game, but have you tried just using a UIAlertView and then doing:

yourAlertView.AlertViewStyle = UIAlertViewStyle.LoginAndPasswordInput;

It'll create a popup login window with the textfields already setup for you.

like image 21
Nande Avatar answered Nov 06 '22 08:11

Nande