Search code examples
c#iosxamarin.iosxamarin-studio

Screen layout out of order in iOS app in Xamarin Studio


I am making basic note taker app using C# and Xamarin. The problem I have is that in in my AddNoteViewController, the layout is in the wrong order. The correct layout should be:

1. Title entry box
2. Description label for text input
3. Text input field

However, the description label is somehow at the top, above the title entry box, despite the layout I specified in my code.

AddNoteViewController_.cs

using System;
using UIKit;

namespace NoteTaker.iOS
{
    public class AddNoteViewController : UIViewController
    {
        public AddNoteViewController () 
        {
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            this.NavigationController.NavigationBar.BarTintColor = UIColor.FromRGB (255, 0, 255);
            this.Title = "New Note";
            this.NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes () { ForegroundColor = UIColor.White };

            this.NavigationController.NavigationBar.TintColor = UIColor.White;
            this.View.BackgroundColor = UIColor.White;

            var titleEntryBox = new UITextField () {
                Frame = new CoreGraphics.CGRect (10, 100, 250, 100),
                BackgroundColor = UIColor.Clear,
                Placeholder = "Enter title...",
                TextColor = UIColor.Black
            };


            var descriptionLabel = new UILabel () {
                Frame = new CoreGraphics.CGRect (10, 100, 250, 35),
                Text = "Enter description below"
            };


            var descriptionEntryBox = new UITextView () {
                Frame = new CoreGraphics.CGRect (10, 220, 250, 100),
                BackgroundColor = UIColor.Clear,
                TextColor = UIColor.Black
            };
            this.View.Add (titleEntryBox);
            this.View.Add (descriptionLabel);
            this.View.Add (descriptionEntryBox);
        }
    }
}

enter image description here


Solution

  • titleEntryBox and descriptionLabel are both positioned at 10,100