how to write ios without storyboard?

mc 5,491 Reputation points
2024-06-12T12:43:50.4366667+00:00

related https://learn.microsoft.com/en-us/answers/questions/1693595/how-to-write-code-in-cs-file-in-xamarin-ios

write in cs file.

Can you tell me how to make ios without storyboard? just cs file?

Developer technologies | .NET | .NET MAUI
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2024-06-14T06:45:53.79+00:00

    Hello,

    Can you tell me how to make ios without storyboard?

    Please create an iOS Application instead of iOS Tabbed Application, then there won't be a storyboard file in your project.

    After that, you can create a TabController as the rootcontroller of the Window.

    AppDelegate

    [Register ("AppDelegate")]
    public class AppDelegate : UIApplicationDelegate {
    	public override UIWindow? Window {
    		get;
    		set;
    	}
     
    	public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
    	{
    		Window = new UIWindow (UIScreen.MainScreen.Bounds);//new window
     
    		var vc = new TabController();
    		Window.RootViewController = vc;//root
    		Window.MakeKeyAndVisible ();
     
    		return true;
    	}
    }
    

    UITabBarController, about how to create UITabrController, you can see Tab Bars and Tab Bar Controllers in Xamarin.iOS - Xamarin | Microsoft Learn (this doc is about Xamarin, it applies to MAUI)

    public class TabController : UITabBarController
    {
     
        UIViewController tab1, tab2, tab3;
     
        public TabController()
        {
            tab1 = new UIViewController();// you can also create the subclass and add controls on that subclass
            tab1.Title = "Green";
            tab1.View.BackgroundColor = UIColor.Green;
     
            tab2 = new UIViewController();
            tab2.Title = "Orange";
            tab2.View.BackgroundColor = UIColor.Orange;
     
            tab3 = new UIViewController();
            tab3.Title = "Red";
            tab3.View.BackgroundColor = UIColor.Red;
     
            var tabs = new UIViewController[] {
                    tab1, tab2, tab3
                };
     
            ViewControllers = tabs;
        }
    }
    

    Best Regards,

    Wenyan Zhang


    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 comments No comments

1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    2024-06-12T16:21:06.86+00:00

    if you are not using Maui forms, to create IOS UI, you will need to Xcode to create the UI.

    You can use the storyboard import task in project file, but you must manually edit the project file as visual studio has no support. and of course you edit storyboard files with Xcode. actually you always used Xcode, VS for Mac would just start it for you. Maui support of storyboards is not well documented. sample using storyboard launch:

    https://github.com/jfversluis/MauiStoryboardSample/blob/main/MauiStoryboardSample/MauiStoryboardSample.csproj

    You can use also UIKit and objective-c or Swift-UI to create the UI which you will build into a native library. You can then use the native library import of visual studio to be able to call the library. If you use Swift-UI, you will need to define objective-c entry points because this is all C# can call.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.