我正在为IOS(xamarin.iOS)创建一个自定义的uicontrol . uicontrol由文本字段和按钮组成 . 我通过扩展UIView来创建自定义控件
Coplexity
文本字段的宽度将由用户给出,并且需要在运行时呈现 .
场景:用户将在应用程序中获得一个表单,他们可以输入控件的宽度,例如,如果用户输入50并点击提交按钮,则在下一页中呈现自定义UIcontrol时,它应该只占50%总屏幕宽度 .
Issue
我需要为文本字段应用自动布局约束 . 并且我添加了约束,只有顶部和左侧约束按预期工作 . 旋转设备时,右边距不会按比例变化
this.AddConstraint (
NSLayoutConstraint.Create(textField,NSLayoutAttribute.Left,NSLayoutRelation.Equal,this, NSLayoutAttribute.Left, 1 , 10)
);
this.AddConstraint (
NSLayoutConstraint.Create(textField,NSLayoutAttribute.Right,NSLayoutRelation.Equal,this, NSLayoutAttribute.Left, 1 , ((UIScreen.MainScreen.Bounds.Width * editTextWidth)/100)+10)
);
this.AddConstraint (
NSLayoutConstraint.Create( textField, NSLayoutAttribute.Top, NSLayoutRelation.Equal,label, NSLayoutAttribute.Top, 1, 30+10)
);
this.AddConstraint (
NSLayoutConstraint.Create(textField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 0, 3 * 10)
);