在 Xamarin.iOS 中设置动态创建的 UITextField 的宽度

Set the width of dynamically created UITextField in Xamarin.iOS

上面写满了 "Let Me Google That For You" 但我试过相信我

我正在 Xamarin iOS 控制器中创建一个 UITextField,我想设置字段的宽度。我正在使用约束来定位各个字段,但我看不到如何将 UITextField 与中心水平对齐放置在一条线上,并给它一个明确的 width.

我在 Xamarin 论坛 iOS AutoLayout in C# without using Interface Builder 中找到了这个 post。它有 LayoutConstraints 的示例并从 C# 应用它们。

我需要的是 NSLayoutAttribute.Width。你会像这样应用它

View.AddConstraint(NSLayoutConstraint.Create(usernameTextBox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.Width, 1, 250.0f));

如果您正在使用来自 Stuart Lodge (MVVM Cross) 的更加友好的 FluentLayouts,您可以这样申请

usernameTextBox.Width().EqualTo(250.0f)