MonoTouch - creating a user interface without Xib

I looked at the Monotouch.dialog stuff and it's pretty cool. However, it has some limitations. I was hoping I could build my application without using Xib files, but I'm not sure how. Without MonoTouch dialog and xib files .... I don't know any other way.

Can anyone point in the right direction?

+3


source to share


1 answer


I didn't know how to do this for a long time, but it's easier than you think! Just add a regular C # class (you don't need to use any special templates), import the MonoTouch.Foundation and MonoTouch.UIKit namespaces, and subclass your new class UIViewController.

It is so simple! You will want to override regular methods like ViewDidLoad, but that should be enough to get you started. As for implementing a UI without using .xib, just create everything programmatically, set the frame and add it to the view (and of course, customize it with properties / methods, etc.)!

You would install something like:

// Table setup
var VersesTable = new UITableView ()
{
    Frame = new RectangleF (0, 0, View.Bounds.Width, View.Bounds.Height - 93),
    BackgroundColor = UIColor.FromPatternImage (Images.BackgroundTexture),
};
View.AddSubview (VersesTable);

      



The hardest part of this process is the frame creation and all the settings (imo).

There is also real code to not use .xib and use MonoTouch.Dialog on the Github page for TweetStation . https://github.com/migueldeicaza/TweetStation/blob/master/TweetStation/Dialogs/Settings.cs

There is a post in the Xamarin forums detailing some examples of using purely C # code (no.xibs) which is very helpful!

+10


source







All Articles