public void AddBaseElements(UIView mainView) { titleLabel = new UILabel(RectangleF.Empty); titleLabel.TextAlignment = UITextAlignment.Center; accessStatus = new UILabel(RectangleF.Empty); accessStatus.TextAlignment = UITextAlignment.Center; requestAccessButton = UIButton.FromType(UIButtonType.RoundedRect); requestAccessButton.TouchUpInside += (s, e) => RequestAccess(); titleLabel.TranslatesAutoresizingMaskIntoConstraints = false; accessStatus.TranslatesAutoresizingMaskIntoConstraints = false; requestAccessButton.TranslatesAutoresizingMaskIntoConstraints = false; // View-level constraints to set constant size values titleLabel.AddConstraints(new [] { NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 14), NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 180), }); accessStatus.AddConstraints(new[] { NSLayoutConstraint.Create(accessStatus, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 18), NSLayoutConstraint.Create(accessStatus, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 180), }); requestAccessButton.AddConstraints(new[] { NSLayoutConstraint.Create(requestAccessButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 14), NSLayoutConstraint.Create(requestAccessButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 180), }); mainView.AddSubview(titleLabel); mainView.AddSubview(accessStatus); mainView.AddSubview(requestAccessButton); // Container view-level constraints to set the position of each subview mainView.AddConstraints(new[] { NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, mainView, NSLayoutAttribute.CenterX, 1, 0), NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, mainView, NSLayoutAttribute.Top, 1, 80), NSLayoutConstraint.Create(accessStatus, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, titleLabel, NSLayoutAttribute.CenterX, 1, 0), NSLayoutConstraint.Create(accessStatus, NSLayoutAttribute.Top, NSLayoutRelation.Equal, titleLabel, NSLayoutAttribute.Bottom, 1, 40), NSLayoutConstraint.Create(requestAccessButton, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, titleLabel, NSLayoutAttribute.CenterX, 1, 0), NSLayoutConstraint.Create(requestAccessButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, accessStatus, NSLayoutAttribute.Bottom, 1, 40), }); }
void AddStepsMessage() { stepsMessage = new UILabel(CGRect.Empty); stepsMessage.TranslatesAutoresizingMaskIntoConstraints = false; stepsMessage.Lines = 0; stepsMessage.Font = UIFont.SystemFontOfSize(UIFont.SmallSystemFontSize); this.View.AddSubview(stepsMessage); stepsMessage.AddConstraints(new [] { NSLayoutConstraint.Create(stepsMessage, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 56), NSLayoutConstraint.Create(stepsMessage, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.Width, 1, 300), }); this.View.AddConstraints(new[] { NSLayoutConstraint.Create(stepsMessage, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, titleLabel, NSLayoutAttribute.CenterX, 1, 0), NSLayoutConstraint.Create(stepsMessage, NSLayoutAttribute.Top, NSLayoutRelation.Equal, requestAccessButton, NSLayoutAttribute.Bottom, 1, 40), }); }