I am using FluentLayout with my Xamarin.iOS project. I created a view:
public class SignInView : UIView
{
private const int headerSpacing = 20;
private const int textFieldSpacing = 10;
private const int textFieldButtonSpacing = 15;
private const int buttonSpacing = 10;
private const int textFieldHeight = 50;
public SignInView()
{
ConstructView();
}
private void ConstructView()
{
var signInLabel = new UILabel() { Text = "sign in" };
var usernameTextField = new UITextField() { Placeholder = "enter username" };
var passwordTextField = new UITextField() { Placeholder = "enter password" };
var signInButton = new UIButton();
var createAccountButton = new UIButton();
signInButton.SetTitle("sign in", UIControlState.Normal);
createAccountButton.SetTitle("create account", UIControlState.Normal);
AddSubviews(signInLabel, usernameTextField, passwordTextField, signInButton, createAccountButton);
this.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
this.AddConstraints(
signInLabel.WithSameTop(this),
signInLabel.WithSameCenterX(this),
usernameTextField.Below(signInLabel, headerSpacing),
usernameTextField.WithSameWidth(this),
usernameTextField.Height().GreaterThanOrEqualTo(textFieldHeight),
passwordTextField.Below(usernameTextField, textFieldSpacing),
passwordTextField.WithSameWidth(this),
passwordTextField.Height().GreaterThanOrEqualTo(textFieldHeight),
signInButton.Below(passwordTextField, textFieldButtonSpacing),
signInButton.WithSameWidth(this),
createAccountButton.Below(signInButton, buttonSpacing),
createAccountButton.WithSameWidth(this)
);
BackgroundColor = UIColor.Red;
}
}
When I place SignInView
in my view, I see everything correctly, but the background isn't red because the height is zero, and nothing is clickable for the same reason. Is there a way to set the height in SignInView
to be the bottom of createAccountButton
?
By the way, what does SubviewsDoNotTranslateAutoresizingMaskIntoConstraints
do? I always need it so that the constraints work, but don't know what it does exactly.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…