Forum Xamarin.iOS

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Programmaticly constraint a subview in a parentView using xamarin ios c#

Marwane.OuardiMarwane.Ouardi USMember
edited April 2017 in Xamarin.iOS

Hello guys i wanna create a subview inside the main View Property of the loginViewcontroller and well
constraint it but it doesnt appear anymore i got just a white screen ...did i miss somsthing or what !!

class LoginViewController : UIViewController
{
private UIView loginView;

    public override void ViewDidLoad()
    {
        this.View.BackgroundColor = UIColor.White;

        // login view 
        loginView = new UIView();
        loginView.BackgroundColor = UIColor.Red;
        loginView.TranslatesAutoresizingMaskIntoConstraints = false;
        loginView.Layer.CornerRadius = 5;
        loginView.Layer.MasksToBounds = true;
        // constraint loginview  to The View
        View.Add(loginView);
    }
    public override void ViewDidLayoutSubviews()
    {
        base.ViewDidLayoutSubviews();
        loginView.CenterXAnchor.ConstraintEqualTo(View.CenterXAnchor).Active = true;
        loginView.CenterYAnchor.ConstraintEqualTo(View.CenterYAnchor).Active=true;
        loginView.WidthAnchor.ConstraintEqualTo(View.WidthAnchor, -24);
        loginView.HeightAnchor.ConstraintEqualTo(150);
    }


}
Sign In or Register to comment.