Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Add a UIButton and set its constraints programmatically?

$
0
0

I have a storyboard which defines most of my UI elements. But I added the Facebook SDK today, and since those elements (LoginButton specifically) are only available in code, I'm trying to add them and set their layout constraints.

In ViewDidLoad I'm instantiating the LoginButton with: (loginView is a property of the controller)

loginView = new LoginButton
        {
            LoginBehavior = LoginBehavior.Native,
            ReadPermissions = readPermissions.ToArray()
        };

Then attempting to set the constraints with:
(ContentView is the name of the view in the storyboard that contains the sibling elements, and SignUpButton is the sibling I want the loginButton to be positioned in relation to)

    var margins = ContentView.LayoutMarginsGuide;

        ContentView.AddSubview(loginView);

        loginView.HeightAnchor.ConstraintEqualTo(SignUpButton.HeightAnchor).Active = true;

        loginView.WidthAnchor.ConstraintEqualTo(SignUpButton.WidthAnchor).Active = true;

        loginView.TopAnchor.ConstraintEqualTo(SignUpButton.BottomAnchor).Active = true;

        loginView.BottomAnchor.ConstraintEqualTo(margins.BottomAnchor).Active = true;

The app builds and then crashes as soon as it opens on my development phone.

Is my issue stemming from the fact that I'm trying to mix a storyboard layout with programmatic layout? I'm lost at this point.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>