public override void ViewDidLoad() { base.ViewDidLoad(); var view = new UIView { BackgroundColor = UIColor.White }; var label = new UILabel { TranslatesAutoresizingMaskIntoConstraints = false, Text = "No Conversation Selected", TextColor = UIColor.FromWhiteAlpha(0.0f, 0.4f), Font = UIFont.PreferredHeadline }; view.AddSubview(label); view.AddConstraint(NSLayoutConstraint.Create(label, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, view, NSLayoutAttribute.CenterX, 1.0f, 0.0f)); view.AddConstraint(NSLayoutConstraint.Create(label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, view, NSLayoutAttribute.CenterY, 1.0f, 0.0f)); View = view; }
public virtual void SubmitChallengeComplete(UIButton button, ResponseModel response) { RemoveOverlay(); Platform.AnimateRotationComplete(button); if (SubmitButtonImage != null) { button.SetBackgroundImage(SubmitButtonImage, UIControlState.Normal); } if (response != null) { UIView overlay = Platform.AddOverlay(response.ResponseCode > 0); if (overlay != null) { ChallengeCompleteView challengeComplete = ChallengeCompleteView.Create(); overlay.AddSubview(challengeComplete); if (response is ChallengeResponseModel) { challengeComplete.Update(overlay, response as ChallengeResponseModel, Challenge, this); } else if (response is ShareResponseModel) { challengeComplete.Update(overlay, response as ShareResponseModel, Challenge, this); } challengeComplete.TranslatesAutoresizingMaskIntoConstraints = false; overlay.AddConstraint(ChallengesConstraints.ChallengesCollectionCellCenterXConstraint(challengeComplete, overlay)); overlay.AddConstraint(ChallengesConstraints.ChallengesConstantTopConstraint(challengeComplete, overlay, 0f)); overlay.AddConstraint(ChallengesConstraints.ChallengesCollectionCellWidthConstraint(challengeComplete, overlay, 0.94f)); overlay.AddConstraint(ChallengesConstraints.ChallengesCollectionCellHeightConstraint(challengeComplete, overlay, 0.81f)); } } }
private UIView GetViewForFooter() { var view = new UIView(new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 120)); var spinner = new UIImageView(); spinner.Image = UIImage.FromBundle("loading-indicator"); var rotationAnimation = new CABasicAnimation { KeyPath = "transform.rotation.z", To = new NSNumber(Math.PI * 2), Duration = 0.7, Cumulative = true, RepeatCount = float.MaxValue }; spinner.Layer.AddAnimation(rotationAnimation, "rotationAnimation"); spinner.TranslatesAutoresizingMaskIntoConstraints = false; view.AddSubview(spinner); view.AddConstraint(FeedConstraints.FeedFooterViewHeight(spinner, view)); view.AddConstraint(FeedConstraints.FeedFooterViewWidth(spinner)); view.AddConstraint(FeedConstraints.FeedFooterViewX(spinner, view)); //view.AddConstraint(FeedConstraints.FeedFooterViewY(spinner, view)); view.AddConstraint(FeedConstraints.FeedFooterTopToView(spinner, view)); return(view); }
/// <summary> /// Creates the layout constraints for the views and fields on the screen. /// </summary> protected void SetupContainerLayoutConstraints(UIView mainView, UIScrollView scrollView, UIView contentView, float scrollViewVerticalOffset, UIView scrollViewBelow, UIView pinScrollViewBottomTo) { // scrollView constraints mainView.AddConstraints(new[] { NSLayoutConstraint.Create(scrollView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, mainView, NSLayoutAttribute.Right, 1, 0), NSLayoutConstraint.Create(scrollView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, mainView, NSLayoutAttribute.Left, 1, 0) }); if (pinScrollViewBottomTo != null) { mainView.AddConstraint(NSLayoutConstraint.Create(scrollView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, pinScrollViewBottomTo, NSLayoutAttribute.Top, 1, 0)); } else { mainView.AddConstraint(NSLayoutConstraint.Create(scrollView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, mainView, NSLayoutAttribute.Bottom, 1, 0)); } if (scrollViewBelow != null) { mainView.AddConstraint(NSLayoutConstraint.Create(scrollView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, scrollViewBelow, NSLayoutAttribute.Bottom, 1, scrollViewVerticalOffset)); } else { mainView.AddConstraint(NSLayoutConstraint.Create(scrollView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, mainView, NSLayoutAttribute.Top, 1, scrollViewVerticalOffset)); } // Add constraints for content view mainView.AddConstraints(new[] { NSLayoutConstraint.Create(contentView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, scrollView, NSLayoutAttribute.Top, 1, 0), NSLayoutConstraint.Create(contentView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, scrollView, NSLayoutAttribute.Right, 1, 0), NSLayoutConstraint.Create(contentView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, scrollView, NSLayoutAttribute.Bottom, 1, 0), NSLayoutConstraint.Create(contentView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, scrollView, NSLayoutAttribute.Left, 1, 0), NSLayoutConstraint.Create(contentView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, mainView, NSLayoutAttribute.Width, 1, 0) }); }
public static void AddWidthAndHeightConstraints(this UIView uiView, float width, float height) { if (uiView == null) { throw new ArgumentNullException(nameof(uiView)); } uiView.TranslatesAutoresizingMaskIntoConstraints = false; uiView.AddConstraint(NSLayoutConstraint.Create(uiView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, height)); uiView.AddConstraint(NSLayoutConstraint.Create(uiView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, width)); }
public ViewMaker() { //Initialize main components _view = new UIView(); _stackView = new UIStackView(); _view.AddSubview(_stackView); //Set view contraints _view.AddConstraint(_stackView.TopAnchor.ConstraintEqualTo(_view.TopAnchor)); _view.AddConstraint(_stackView.BottomAnchor.ConstraintEqualTo(_view.BottomAnchor)); _view.AddConstraint(_stackView.LeftAnchor.ConstraintEqualTo(_view.LeftAnchor)); _view.AddConstraint(_stackView.RightAnchor.ConstraintEqualTo(_view.RightAnchor)); }
public static UIView WithConstraint(this UIView constrainedView, UIView view1, NSLayoutAttribute attribute1, NSLayoutRelation relation, UIView view2, NSLayoutAttribute attribute2, nfloat multiplier, nfloat constant, [CallerMemberName] string identifier = "", float?priority = null) { if (view1 != null && view1 != constrainedView) { view1.TranslatesAutoresizingMaskIntoConstraints = false; } if (view2 != null && view2 != constrainedView) { view2.TranslatesAutoresizingMaskIntoConstraints = false; } var constraint = NSLayoutConstraint.Create(view1, attribute1, relation, view2, attribute2, multiplier, constant); if (!string.IsNullOrEmpty(identifier)) { constraint.SetIdentifier(identifier); } if (priority.HasValue) { constraint.Priority = priority.Value; } constrainedView.AddConstraint(constraint); return(constrainedView); }
public static void FillWidth(this UIView view, UIView parent, float height, float top = 0, float left = 0, float right = 0) { view.TranslatesAutoresizingMaskIntoConstraints = false; parent.AddConstraint( NSLayoutConstraint.Create(view, NSLayoutAttribute.Top, NSLayoutRelation.Equal, parent, NSLayoutAttribute.Top, 1, top)); parent.AddConstraint( NSLayoutConstraint.Create(view, NSLayoutAttribute.Left, NSLayoutRelation.Equal, parent, NSLayoutAttribute.Left, 1, left)); parent.AddConstraint( NSLayoutConstraint.Create(view, NSLayoutAttribute.Right, NSLayoutRelation.Equal, parent, NSLayoutAttribute.Right, 1, right)); parent.AddConstraint( NSLayoutConstraint.Create(view, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 0, height) ); }
private void InitDialogView() { Frame = UIScreen.MainScreen.Bounds; BackgroundColor = UIColor.Black.ColorWithAlpha(0.35f); _dialogView = new UIView(new CGRect(0, 0, Frame.Width - (_dialogMargin * 2), 0)) { BackgroundColor = Theme.LoginColor, Center = this.Center, Alpha = 0, }; _dialogView.Layer.CornerRadius = 10; var title = new UILabel { Text = _title, Font = UIFont.BoldSystemFontOfSize(16), TranslatesAutoresizingMaskIntoConstraints = false, TextAlignment = UITextAlignment.Center, Lines = 0, TextColor = Theme.GetContrastBasedColor(Theme.LoginColor) }; if (_hasTitle) { _dialogView.Add(title); _dialogView.AddConstraints(new [] { NSLayoutConstraint.Create(title, NSLayoutAttribute.Top, NSLayoutRelation.Equal, _dialogView, NSLayoutAttribute.Top, 1f, _dialogEdgeConstraint), NSLayoutConstraint.Create(title, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, _dialogView, NSLayoutAttribute.Leading, 1f, _dialogEdgeConstraint), NSLayoutConstraint.Create(title, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, _dialogView, NSLayoutAttribute.Trailing, 1f, -_dialogEdgeConstraint), }); } _messageView = new UILabel { Text = _message, Font = UIFont.SystemFontOfSize(16), TranslatesAutoresizingMaskIntoConstraints = false, TextAlignment = UITextAlignment.Center, Lines = 0, TextColor = Theme.GetContrastBasedColor(Theme.LoginColor) }; _dialogView.Add(_messageView); _dialogView.AddConstraint(_hasTitle ? NSLayoutConstraint.Create(_messageView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, title, NSLayoutAttribute.Bottom, 1f, _globalMargin) : NSLayoutConstraint.Create(_messageView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, _dialogView, NSLayoutAttribute.Top, 1f, _dialogEdgeConstraint)); _dialogView.AddConstraints(new [] { NSLayoutConstraint.Create(_messageView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, _dialogView, NSLayoutAttribute.Leading, 1f, _dialogEdgeConstraint), NSLayoutConstraint.Create(_messageView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, _dialogView, NSLayoutAttribute.Trailing, 1f, -_dialogEdgeConstraint), }); AddSubviews(_dialogView); }
/// <summary> /// Replaces the constraint with. /// Will not call layout if needed /// </summary> /// <param name="view">View.</param> /// <param name="oldConstraint">Old constraint.</param> /// <param name="newConstraint">New constraint.</param> public static void ReplaceConstraintWith(this UIView view, NSLayoutConstraint oldConstraint, NSLayoutConstraint newConstraint) { view.RemoveConstraint(oldConstraint); view.AddConstraint(newConstraint); }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Picker> e) { base.OnElementChanged(e); var width = UIScreen.MainScreen.Bounds.Width; var entry = Control; entry.EditingDidBegin += OnStarted; entry.EditingDidEnd += OnEnded; entry.EditingChanged += OnEditing; pickerView = new UIPickerView(); pickerView.Frame = new CGRect(0, 0, width, 320); var accessoryView = new UIView(new CGRect(0, 0, width, 144)); UIButton btn = new UIButton(UIButtonType.System); btn.SetTitle("Done", UIControlState.Normal); btn.AddTarget((sender, args) => { var s = (PickerSource)pickerView.Model; if (s.SelectedIndex == -1 && Element.Items != null && Element.Items.Count > 0) { UpdatePickerSelectedIndex(0); } UpdatePickerFromModel(s); entry.ResignFirstResponder(); }, UIControlEvent.TouchUpInside); accessoryView.AddSubview(btn); btn.TranslatesAutoresizingMaskIntoConstraints = false; accessoryView.AddConstraint(NSLayoutConstraint.Create(btn, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, accessoryView, NSLayoutAttribute.Trailing, 1, -10)); accessoryView.AddConstraint(NSLayoutConstraint.Create(btn, NSLayoutAttribute.Top, NSLayoutRelation.Equal, accessoryView, NSLayoutAttribute.Top, 1, 5)); entry.InputView = pickerView; entry.InputAccessoryView = accessoryView; _defaultTextColor = entry.TextColor; pickerView.Model = new PickerSource(this); UpdatePicker(); UpdateTextColor(); }
static void InstallEqual(NSLayoutAttribute attribute, UIView first, UIView second) { UIView commonAncestor = AssertCommonAncestor(first, second); var c = CreateEqual(attribute, first, second); commonAncestor.AddConstraint(c); }
NSLayoutConstraint SetConstant(UIView view, NSLayoutAttribute attr, nfloat value) { var c = NSLayoutConstraint.Create(view, attr, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 0, value); view.AddConstraint(c); return(c); }
// Custom Methods protected void StyleNavigationBar(UIColor primaryColor, UIColor primaryDarkColor, string title) { this.NavigationController.SetNavigationBarHidden(true, false); UINavigationBar newNavBar = new UINavigationBar(new CGRect(0, 0, this.View.Bounds.Width, 104.0)); newNavBar.BarTintColor = primaryColor; newNavBar.TintColor = UIColor.White; newNavBar.Translucent = false; NavItem = new UINavigationItem(); NavItem.HidesBackButton = true; var titleView = new UIView(new CGRect(0, 0, this.View.Bounds.Width, 88.0f)); var titleLabel = new UILabel(new CGRect(0, 0, this.View.Bounds.Width, 88.0f)); titleLabel.Font = UIFont.SystemFontOfSize(17, UIFontWeight.Semibold); titleLabel.TextColor = UIColor.White; titleLabel.AdjustsFontSizeToFitWidth = true; titleLabel.Text = title; titleView.AddSubview(titleLabel); titleView.AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleBottomMargin; titleLabel.TranslatesAutoresizingMaskIntoConstraints = false; NSLayoutConstraint trailing = NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, titleView, NSLayoutAttribute.Trailing, 1.0f, 0.0f); NSLayoutConstraint leading = NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, titleView, NSLayoutAttribute.Leading, 1.0f, 0.0f); NSLayoutConstraint bottom = NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, titleView, NSLayoutAttribute.Bottom, 1.0f, 0.0f); NSLayoutConstraint top = NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, titleView, NSLayoutAttribute.Top, 1.0f, 0.0f); titleView.AddConstraint(trailing); titleView.AddConstraint(leading); titleView.AddConstraint(bottom); titleView.AddConstraint(top); NavItem.TitleView = titleView; var statusBarView = new UIView(new CGRect(0, 0, this.View.Bounds.Width, 20)); statusBarView.BackgroundColor = primaryDarkColor; newNavBar.SetItems(new[] { NavItem }, false); newNavBar.AddSubview(statusBarView); this.View.AddSubview(newNavBar); }
public static void Vertically(UIView parent, UIView[] children, nfloat top = default(nfloat), nfloat bottom = default(nfloat), nfloat spacing = default(nfloat)) { prepareForConstraint(parent, children); if (0 < children.Length) { parent.AddConstraint(NSLayoutConstraint.Create( view1: children[0], attribute1: NSLayoutAttribute.Top, relation: NSLayoutRelation.Equal, view2: parent, attribute2: NSLayoutAttribute.Top, multiplier: 1, constant: top)); for (var i = 1; i < children.Length; i++) { parent.AddConstraint(NSLayoutConstraint.Create( view1: children[i], attribute1: NSLayoutAttribute.Top, relation: NSLayoutRelation.Equal, view2: children[i - 1], attribute2: NSLayoutAttribute.Bottom, multiplier: 1, constant: spacing)); parent.AddConstraint(NSLayoutConstraint.Create( view1: children[i], attribute1: NSLayoutAttribute.Height, relation: NSLayoutRelation.Equal, view2: children[0], attribute2: NSLayoutAttribute.Height, multiplier: 1, constant: 0)); } parent.AddConstraint(NSLayoutConstraint.Create( view1: children[children.Length - 1], attribute1: NSLayoutAttribute.Bottom, relation: NSLayoutRelation.Equal, view2: parent, attribute2: NSLayoutAttribute.Bottom, multiplier: 1, constant: -bottom)); } }
public static void Horizontally(UIView parent, UIView[] children, nfloat left = default(nfloat), nfloat right = default(nfloat), nfloat spacing = default(nfloat)) { prepareForConstraint(parent, children); if (0 < children.Length) { parent.AddConstraint(NSLayoutConstraint.Create( view1: children[0], attribute1: NSLayoutAttribute.Left, relation: NSLayoutRelation.Equal, view2: parent, attribute2: NSLayoutAttribute.Left, multiplier: 1, constant: left)); for (var i = 1; i < children.Length; i++) { parent.AddConstraint(NSLayoutConstraint.Create( view1: children[i], attribute1: NSLayoutAttribute.Left, relation: NSLayoutRelation.Equal, view2: children[i - 1], attribute2: NSLayoutAttribute.Right, multiplier: 1, constant: spacing)); parent.AddConstraint(NSLayoutConstraint.Create( view1: children[i], attribute1: NSLayoutAttribute.Width, relation: NSLayoutRelation.Equal, view2: children[0], attribute2: NSLayoutAttribute.Width, multiplier: 1, constant: 0)); } parent.AddConstraint(NSLayoutConstraint.Create( view1: children[children.Length - 1], attribute1: NSLayoutAttribute.Right, relation: NSLayoutRelation.Equal, view2: parent, attribute2: NSLayoutAttribute.Right, multiplier: 1, constant: -right)); } }
public static NSLayoutConstraint SetCenterYContraintTo(this UIView childView, UIView superView, float margin = 0, NSLayoutRelation relation = NSLayoutRelation.Equal, int priority = 1000) { var constraint = NSLayoutConstraint.Create(superView, NSLayoutAttribute.CenterY, relation, childView, NSLayoutAttribute.CenterY, 1, margin); constraint.Priority = priority; superView.AddConstraint(constraint); return(constraint); }
/** * Displays a loading dialog with a loading spinner, and a message * * - parameter message: The message displayed to the user while its loading * - returns: The Loading Dialog */ public static NBMaterialLoadingDialog Show(NBMaterialLoadingDialogSettings settings) { var containerView = new UIView(); var circularLoadingActivity = new NBMaterialCircularActivityIndicator(); var loadingLabel = new UILabel(); //circularLoadingActivity.initialize() circularLoadingActivity.TranslatesAutoresizingMaskIntoConstraints = false; circularLoadingActivity.LineWidth = 3.5f; circularLoadingActivity.TintColor = NBConfig.AccentColor; containerView.AddSubview(circularLoadingActivity); loadingLabel.TranslatesAutoresizingMaskIntoConstraints = false; loadingLabel.Font = UIFontExtensions.ArialFont(14); loadingLabel.TextColor = NBConfig.PrimaryTextDark; loadingLabel.Text = settings.Text; // TODO: Add support for multiple lines, probably need to fix the dynamic dialog height todo first loadingLabel.Lines = 0; containerView.AddSubview(loadingLabel); // Setup constraints NSMutableDictionary constraintViews = new NSMutableDictionary(); constraintViews.SetValueForKey(circularLoadingActivity, new NSString("spinner")); constraintViews.SetValueForKey(loadingLabel, new NSString("label")); containerView.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[spinner(==32)]-16-[label]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, metrics: null, views: constraintViews)); containerView.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:[spinner(==32)]", NSLayoutFormatOptions.DirectionLeadingToTrailing, metrics: null, views: constraintViews)); // Center Y needs to be set manually, not through VFL containerView.AddConstraint( NSLayoutConstraint.Create( circularLoadingActivity, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, containerView, NSLayoutAttribute.CenterY, multiplier: 1, constant: 0)); containerView.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|[label]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, metrics: null, views: constraintViews)); // Initialize dialog and display var dialog = new NBMaterialLoadingDialog(); settings.Content = containerView; settings.DialogHeight = settings.DialogHeight ?? dialog.kMinimumHeight; dialog.SetLoadingLabel(loadingLabel); dialog.ShowDialog(settings); // Start spinner circularLoadingActivity.StartAnimating(); return(dialog); }
public static void Height(UIView parent, UIView child, nfloat height = default(nfloat)) { prepareForConstraint(parent, child); parent.AddConstraint(NSLayoutConstraint.Create( view1: child, attribute1: NSLayoutAttribute.Height, relation: NSLayoutRelation.Equal, multiplier: 1, constant: height)); }
private void PinTopRelativeToStart(UIView view, double topOffset) { _mainView.AddConstraint(NSLayoutConstraint.Create( view, NSLayoutAttribute.Top, NSLayoutRelation.Equal, _allDayItemsRow, NSLayoutAttribute.Bottom, 1, (float)topOffset)); }
public static UIView SetMinimumHeight(this UIView view, float minHeight) { view.AddConstraint(NSLayoutConstraint.Create( view, NSLayoutAttribute.Height, NSLayoutRelation.GreaterThanOrEqual, 1, minHeight)); return(view); }
public static void Horizontally(UIView parent, UIView child, nfloat left = default(nfloat), nfloat right = default(nfloat)) { prepareForConstraint(parent, child); parent.AddConstraint(NSLayoutConstraint.Create( view1: child, attribute1: NSLayoutAttribute.Left, relation: NSLayoutRelation.Equal, view2: parent, attribute2: NSLayoutAttribute.Left, multiplier: 1, constant: left)); parent.AddConstraint(NSLayoutConstraint.Create( view1: child, attribute1: NSLayoutAttribute.Right, relation: NSLayoutRelation.Equal, view2: parent, attribute2: NSLayoutAttribute.Right, multiplier: 1, constant: -right)); }
public static NSLayoutConstraint SetHeight(this UIView view, nfloat height) { var constraint = NSLayoutConstraint.Create( view, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, height); view.AddConstraint(constraint); constraint.Active = true; return(constraint); }
public static void Vertically(UIView parent, UIView child, nfloat top = default(nfloat), nfloat bottom = default(nfloat)) { prepareForConstraint(parent, child); parent.AddConstraint(NSLayoutConstraint.Create( view1: child, attribute1: NSLayoutAttribute.Top, relation: NSLayoutRelation.Equal, view2: parent, attribute2: NSLayoutAttribute.Top, multiplier: 1, constant: top)); parent.AddConstraint(NSLayoutConstraint.Create( view1: child, attribute1: NSLayoutAttribute.Bottom, relation: NSLayoutRelation.Equal, view2: parent, attribute2: NSLayoutAttribute.Bottom, multiplier: 1, constant: -bottom)); }
public override void AwakeFromNib() { base.AwakeFromNib(); view = new UIView(); view.BackgroundColor = borderColor; view.TranslatesAutoresizingMaskIntoConstraints = false; AddSubview(view); view.AddConstraint(NSLayoutConstraint.Create( view1: view, attribute1: NSLayoutAttribute.Height, relation: NSLayoutRelation.Equal, view2: null, attribute2: NSLayoutAttribute.Height, multiplier: 1, constant: 1 ) ); AddConstraint(NSLayoutConstraint.Create( view1: view, attribute1: NSLayoutAttribute.Left, relation: NSLayoutRelation.Equal, view2: this, attribute2: NSLayoutAttribute.Left, multiplier: 1, constant: 0 ) ); AddConstraint(NSLayoutConstraint.Create( view1: view, attribute1: NSLayoutAttribute.Right, relation: NSLayoutRelation.Equal, view2: this, attribute2: NSLayoutAttribute.Right, multiplier: 1, constant: 0 ) ); AddConstraint(NSLayoutConstraint.Create( view1: view, attribute1: NSLayoutAttribute.Bottom, relation: NSLayoutRelation.Equal, view2: this, attribute2: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0 ) ); }
public static UIView SetMaxWidth(this UIView view, nfloat maxWidth) { view.AddConstraint(NSLayoutConstraint.Create( view, NSLayoutAttribute.Width, NSLayoutRelation.LessThanOrEqual, 1, maxWidth)); return(view); }
public static void SetCenterXContraintTo(this UIView childView, UIView superView, float margin = 0, NSLayoutRelation relation = NSLayoutRelation.Equal) { superView.AddConstraint(NSLayoutConstraint.Create( superView, NSLayoutAttribute.CenterX, relation, childView, NSLayoutAttribute.CenterX, 1, margin)); }
private static void AddBottomConstraint(UIView parent, CodeStringView codeStringView, UIView centerCodeString, int column) { var distanceFromCenter = GetDistanceFromCenter(column); var bottomConstraint = NSLayoutConstraint.Create( codeStringView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, centerCodeString, NSLayoutAttribute.Bottom, 1, -distanceFromCenter); parent.AddConstraint(bottomConstraint); }
/// <summary> /// Adds a constraint to set the base line of <param name="child"/> to top + <param name="baseLine"/> of parent view /// </summary> /// <param name="parent">The View within the control</param> /// <param name="child">The control to set to top</param> /// <param name="baseLine">Offest</param> /// <param name="setTranslatesAutoresizingMaskIntoConstraintsToFalse"></param> public static NSLayoutConstraint AddBaseLineConstraint(UIView parent, UIView child, int baseLine, bool setTranslatesAutoresizingMaskIntoConstraintsToFalse = true) { if (setTranslatesAutoresizingMaskIntoConstraintsToFalse) { child.TranslatesAutoresizingMaskIntoConstraints = false; } var constraint = NSLayoutConstraint.Create(child, NSLayoutAttribute.Baseline, NSLayoutRelation.Equal, parent, NSLayoutAttribute.Top, 1, baseLine); parent.AddConstraint(constraint); return(constraint); }
/// <summary> /// Adds a constraint for horizontal center layout /// </summary> /// <param name="parent">The View within the control</param> /// <param name="child">The control to center</param> /// <param name="multiplier"></param> /// <param name="setTranslatesAutoresizingMaskIntoConstraintsToFalse"></param> public static void AddPercentHeightConstraint(UIView parent, UIView child, float multiplier, bool setTranslatesAutoresizingMaskIntoConstraintsToFalse = true) { if (setTranslatesAutoresizingMaskIntoConstraintsToFalse) { child.TranslatesAutoresizingMaskIntoConstraints = false; } var constraint = NSLayoutConstraint.Create(child, NSLayoutAttribute.Height, NSLayoutRelation.Equal, parent, NSLayoutAttribute.Height, multiplier, 0); parent.AddConstraint(constraint); }
public static NSLayoutConstraint SetHeight(UIView target, nfloat height) { if (target != null) { NSLayoutConstraint constraint = NSLayoutConstraint.Create ( target, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, height ); target.AddConstraint(constraint); return constraint; } return null; }
/// <summary> /// STATCODE_CA1709 /// </summary> public static NSLayoutConstraint SetRelativeHeight(UIView ancestor, UIView outer, UIView inner, nfloat ratio) { if (ancestor != null) { NSLayoutConstraint constraint = NSLayoutConstraint.Create ( inner, NSLayoutAttribute.Height, NSLayoutRelation.Equal, outer, NSLayoutAttribute.Height, ratio, 0 ); ancestor.AddConstraint(constraint); return constraint; } return null; }
public static NSLayoutConstraint SetWidth(UIView target, nfloat width) { if (target != null) { NSLayoutConstraint constraint = NSLayoutConstraint.Create ( target, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, width ); target.AddConstraint(constraint); return constraint; } return null; }
public static NSLayoutConstraint FollowControlHorizontally(UIView ancestor, UIView first, UIView next, nfloat margin) { NSLayoutConstraint constraint = NSLayoutConstraint.Create ( next, NSLayoutAttribute.Left, NSLayoutRelation.Equal, first, NSLayoutAttribute.Right, 1, margin ); ancestor.AddConstraint(constraint); return constraint; }
public static NSLayoutConstraint FollowControlVertically(UIView ancestor, UIView first, UIView next, nfloat margin) { if (ancestor != null) { NSLayoutConstraint constraint = NSLayoutConstraint.Create ( next, NSLayoutAttribute.Top, NSLayoutRelation.Equal, first, NSLayoutAttribute.Bottom, 1, margin ); ancestor.AddConstraint(constraint); return constraint; } return null; }
public static NSLayoutConstraint AlignTops ( UIView ancestor, UIView fixedControl, UIView controlToAlign ) { NSLayoutConstraint constraint = NSLayoutConstraint.Create ( controlToAlign, NSLayoutAttribute.Top, NSLayoutRelation.Equal, fixedControl, NSLayoutAttribute.Top, 1, 0 ); ancestor.AddConstraint(constraint); return constraint; }
public static NSLayoutConstraint CenterControlVertically(UIView outer, UIView inner) { if (outer != null) { NSLayoutConstraint constraint = NSLayoutConstraint.Create ( inner, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, outer, NSLayoutAttribute.CenterY, 1, 0 ); outer.AddConstraint(constraint); return constraint; } return null; }
public override void LoadView () { UIView view = new UIView (); UIButton newButton = UIButton.FromType (UIButtonType.System); newButton.TranslatesAutoresizingMaskIntoConstraints = false; newButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center; newButton.SetTitle ("New Game", UIControlState.Normal); newButton.TitleLabel.Font = UIFont.PreferredBody; newButton.TouchUpInside += newGame; view.AddSubview (newButton); UIButton pauseButton = UIButton.FromType (UIButtonType.System); pauseButton.TranslatesAutoresizingMaskIntoConstraints = false; pauseButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center; pauseButton.SetTitle ("Pause", UIControlState.Normal); pauseButton.TitleLabel.Font = UIFont.PreferredBody; pauseButton.TouchUpInside += togglePause; view.AddSubview (pauseButton); gameView = new TTTGameView () { ImageForPlayer = ImageForPlayer, ColorForPlayer = ColorForPlayer, CanSelect = CanSelect, DidSelect = DidSelect, TranslatesAutoresizingMaskIntoConstraints = false, Game = Profile.CurrentGame }; view.AddSubview (gameView); float topHeight = UIApplication.SharedApplication.StatusBarFrame.Size.Height; UITabBar tabBar = TabBarController.TabBar; float bottomHeight = tabBar.Translucent ? tabBar.Frame.Size.Height : 0; NSDictionary metrics = NSDictionary.FromObjectsAndKeys ( new NSNumber[] { new NSNumber (topHeight + ControllerMargin), new NSNumber (bottomHeight + ControllerMargin), new NSNumber (ControllerMargin) }, new NSString[] { new NSString ("topHeight"), new NSString ("bottomHeight"), new NSString ("margin") } ); NSDictionary bindings = NSDictionary.FromObjectsAndKeys ( new NSObject[] { newButton, pauseButton, gameView }, new NSString [] { new NSString ("newButton"), new NSString ("pauseButton"), new NSString ("gameView") } ); view.AddConstraints (NSLayoutConstraint.FromVisualFormat ( "|-margin-[gameView]-margin-|", (NSLayoutFormatOptions)0, metrics, bindings )); view.AddConstraints (NSLayoutConstraint.FromVisualFormat ( "|-margin-[pauseButton(==newButton)]-[newButton]-margin-|", (NSLayoutFormatOptions)0, metrics, bindings )); view.AddConstraints (NSLayoutConstraint.FromVisualFormat ( "V:|-topHeight-[gameView]-margin-[newButton]-bottomHeight-|", (NSLayoutFormatOptions)0, metrics, bindings )); view.AddConstraint (NSLayoutConstraint.Create (pauseButton, NSLayoutAttribute.Baseline, NSLayoutRelation.Equal, newButton, NSLayoutAttribute.Baseline, 1f, 0f)); View = view; }
public static NSLayoutConstraint AlignCentersVertically(UIView ancestor, UIView fixedControl, UIView controlToCenter) { NSLayoutConstraint constraint = NSLayoutConstraint.Create ( controlToCenter, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, fixedControl, NSLayoutAttribute.CenterY, 1, 0 ); ancestor.AddConstraint(constraint); return constraint; }
public static NSLayoutConstraint AttachToParentBottom(UIView parent, UIView child, nfloat margin) { if (parent != null) { NSLayoutConstraint constraint = NSLayoutConstraint.Create ( parent, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, child, NSLayoutAttribute.Bottom, 1, margin ); parent.AddConstraint(constraint); return constraint; } return null; }
void AddViews() { if (toolbar == null) { toolbar = new UIToolbar(); View.AddSubview(toolbar); toolbar.TranslatesAutoresizingMaskIntoConstraints = false; View.AddConstraint(NSLayoutConstraint.Create(toolbar, NSLayoutAttribute.LeadingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1, 0)); View.AddConstraint(NSLayoutConstraint.Create(toolbar, NSLayoutAttribute.TrailingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Trailing, 1, 0)); View.AddConstraint(NSLayoutConstraint.Create(toolbar, NSLayoutAttribute.BottomMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0)); View.AddConstraint(NSLayoutConstraint.Create(toolbar, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.Height, 1, 44)); } if (webView == null) { webView = new CustomWebView(); View.AddSubview(webView); webView.TranslatesAutoresizingMaskIntoConstraints = false; View.AddConstraint(NSLayoutConstraint.Create(webView, NSLayoutAttribute.LeadingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1, 0)); View.AddConstraint(NSLayoutConstraint.Create(webView, NSLayoutAttribute.TrailingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Trailing, 1, 0)); View.AddConstraint(NSLayoutConstraint.Create(webView, NSLayoutAttribute.BottomMargin, NSLayoutRelation.Equal, toolbar, NSLayoutAttribute.Top, 1, 0)); View.AddConstraint(NSLayoutConstraint.Create(webView, NSLayoutAttribute.TopMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, 0)); } if (activityView == null) { activityView = new UIView(); activityView.Hidden = true; activityView.BackgroundColor = UIColor.Black.ColorWithAlpha(0.2f); View.AddSubview(activityView); activityView.TranslatesAutoresizingMaskIntoConstraints = false; View.AddConstraint(NSLayoutConstraint.Create(activityView, NSLayoutAttribute.LeadingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1, 0)); View.AddConstraint(NSLayoutConstraint.Create(activityView, NSLayoutAttribute.TrailingMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Trailing, 1, 0)); View.AddConstraint(NSLayoutConstraint.Create(activityView, NSLayoutAttribute.BottomMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0)); View.AddConstraint(NSLayoutConstraint.Create(activityView, NSLayoutAttribute.TopMargin, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, 0)); UIActivityIndicatorView indicator = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge); indicator.StartAnimating(); activityView.AddSubview(indicator); indicator.TranslatesAutoresizingMaskIntoConstraints = false; activityView.AddConstraint(NSLayoutConstraint.Create(indicator, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, activityView, NSLayoutAttribute.CenterX, 1, 0)); activityView.AddConstraint(NSLayoutConstraint.Create(indicator, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, activityView, NSLayoutAttribute.CenterY, 1, 0)); //activityView.AddConstraint(NSLayoutConstraint.Create(indicator, NSLayoutAttribute.Width, NSLayoutRelation.Equal, indicator, NSLayoutAttribute.Width, 1, 80)); //activityView.AddConstraint(NSLayoutConstraint.Create(indicator, NSLayoutAttribute.Height, NSLayoutRelation.Equal, indicator, NSLayoutAttribute.Height, 1, 80)); } }
public static NSLayoutConstraint AttachToBottomLevelGuide ( UIView parent, IUILayoutSupport bottomGuide, UIView child, nfloat margin ) { NSLayoutConstraint result = NSLayoutConstraint.Create ( bottomGuide, NSLayoutAttribute.Top, NSLayoutRelation.Equal, child, NSLayoutAttribute.Bottom, 1, margin ); parent.AddConstraint(result); return result; }
void CreateNickNameView() { titleContainer = new UIView (new CGRect(0, 0, 200, 20)); nickNameLbl = new UILabel { TranslatesAutoresizingMaskIntoConstraints = false, TextAlignment = UITextAlignment.Center, }; nickNameEditIcon = new UIImageView { TranslatesAutoresizingMaskIntoConstraints = false, Image = UIImage.FromBundle ("editNickName"), }; nickNameInput = new UITextField { TranslatesAutoresizingMaskIntoConstraints = false, ShouldReturn = ShouldReturn, TextAlignment = UITextAlignment.Center, BorderStyle = UITextBorderStyle.RoundedRect, BackgroundColor = UIColor.White, }; nickNameInput.Ended += NickNameEditingEnded; titleContainer.AddSubviews (nickNameLbl, nickNameInput, nickNameEditIcon); Center(nickNameLbl); titleContainer.AddConstraint (PlaceOnTheRight (nickNameLbl, nickNameEditIcon, 10)); CenterVertically (nickNameEditIcon); PinLeftRightEdges (nickNameInput); CenterVertically (nickNameInput); tap = new UITapGestureRecognizer (StartEditNickName) { NumberOfTapsRequired = 1 }; titleContainer.AddGestureRecognizer (tap); ShowNormalNickNameVisualState (); }
public static NSLayoutConstraint SetRelativeWidth(UIView ancestor, UIView outer, UIView inner, nfloat ratio) { NSLayoutConstraint constraint = NSLayoutConstraint.Create ( inner, NSLayoutAttribute.Width, NSLayoutRelation.Equal, outer, NSLayoutAttribute.Width, ratio, 0 ); ancestor.AddConstraint(constraint); return constraint; }
public override void ViewDidLoad() { base.ViewDidLoad (); //scrollView = stackView.Superview as UIScrollView; //scrollView.KeyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag; //scrollView.ScrollEnabled = true; // Set up Navigation Bar var saveButton = new UIBarButtonItem (UIBarButtonSystemItem.Save, save); var cancelButton = new UIBarButtonItem (UIBarButtonSystemItem.Cancel, cancel); NavigationItem.Title = "New Medication:"; NavigationItem.RightBarButtonItem = saveButton; NavigationItem.HidesBackButton = true; NavigationItem.LeftBarButtonItem = cancelButton; //NSNotificationCenter.DefaultCenter.AddObserver (this, new ObjCRuntime.Selector("keyboardDidAppear:"), UIKeyboard.DidShowNotification, null); //NSNotificationCenter.DefaultCenter.AddObserver (this, new ObjCRuntime.Selector ("keyboardWillDissapear:"), UIKeyboard.WillHideNotification, null); // Set up the date formatter dateFormat = new NSDateFormatter(); dateFormat.DateStyle = NSDateFormatterStyle.None; dateFormat.TimeStyle = NSDateFormatterStyle.Short; // Set up new pet form nameField = new UITextField(); nameField.Text = "Medication Name"; nameField.BorderStyle = UITextBorderStyle.RoundedRect; nameField.ReturnKeyType = UIReturnKeyType.Done; medTypeLabel = new UILabel (); medTypeLabel.Text = "Type of Medication"; medTypeButton = new UIButton (UIButtonType.RoundedRect); medTypeButton.AddTarget (editMedType, UIControlEvent.TouchUpInside); medTypeButton.SetTitle ("Pill", UIControlState.Normal); medTypeButton.TitleLabel.Font = medTypeButton.TitleLabel.Font.WithSize (medTypeLabel.Font.PointSize); medTypePicker = new UIPickerView (); medTypePicker.Delegate = new MedTypePickerDelegate (this); medTypePicker.DataSource = new MedTypePickerDataSource (); freqLabel = new UILabel (); freqLabel.Text = "Frequency"; freqTextField = new UITextField (); freqTextField.Text = "1"; freqTextField.KeyboardType = UIKeyboardType.NumberPad; freqTextField.BorderStyle = UITextBorderStyle.RoundedRect; freqTextField.Enabled = false; freqTextField.AddTarget (freqTextFieldChanged, UIControlEvent.EditingDidEnd | UIControlEvent.EditingDidEndOnExit); freqStepper = new UIStepper (); freqStepper.Value = 1; freqStepper.MinimumValue = 1; freqStepper.Enabled = false; freqStepper.AddTarget (freqStepperIncremented, UIControlEvent.ValueChanged); UIStackView freqStackView = new UIStackView (new UIView[] { freqTextField, freqStepper }); freqStackView.Spacing = 8; freqStackView.Axis = UILayoutConstraintAxis.Horizontal; freqButton = new UIButton (UIButtonType.RoundedRect); freqButton.SetTitle ("Daily", UIControlState.Normal); freqButton.TitleLabel.Font = freqButton.TitleLabel.Font.WithSize (medTypeLabel.Font.PointSize); freqButton.AddTarget (editFrequency, UIControlEvent.TouchUpInside); freqPicker = new UIPickerView (); freqPicker.Delegate = new MedFreqPickerDelegate (this); freqPicker.DataSource = new MedFreqPickerDataSource (); timePicker = new UIDatePicker (); gregorian = new NSCalendar (NSCalendarType.Gregorian); timePicker.Date = gregorian.DateBySettingsHour (9, 0, 0, NSDate.Now, NSCalendarOptions.MatchNextTime); timePicker.Mode = UIDatePickerMode.Time; timePicker.AddTarget (timePickerChanged, UIControlEvent.AllEvents); UILabel timeLabel = new UILabel (); timeLabel.Text = "Time"; timeButtons = new UIButton[1]; timeDates = new NSDate[1]; timeDates [0] = gregorian.DateBySettingsHour (9, 0, 0, NSDate.Now, NSCalendarOptions.MatchNextTime); timeButtons [0] = new UIButton (UIButtonType.RoundedRect); timeButtons [0].SetTitle ("9:00 AM", UIControlState.Normal); timeButtons [0].AddTarget (openTimePicker, UIControlEvent.TouchUpInside); timeStack = new UIStackView (); timeStack.Alignment = UIStackViewAlignment.Leading; timeStack.Distribution = UIStackViewDistribution.FillProportionally; timeStack.Spacing = 5; timeStack.Axis = UILayoutConstraintAxis.Vertical; timeStack.AddArrangedSubview (timeLabel); foreach (var button in timeButtons) { timeStack.AddArrangedSubview (button); } timeStack.AddArrangedSubview (timePicker); timePicker.Hidden = true; dayLabel = new UILabel (); dayLabel.Text = "Day"; dayLabel.Hidden = true; dayButton = new UIButton (UIButtonType.RoundedRect); var day = gregorian.GetComponentFromDate (NSCalendarUnit.Weekday, NSDate.Now); dayButton.SetTitle (gregorian.WeekdaySymbols[day], UIControlState.Normal); dayButton.AddTarget (openDayPicker, UIControlEvent.TouchUpInside); dayButton.Hidden = true; dayPicker = new UIDatePicker (); dayPicker.Mode = UIDatePickerMode.Date; dayPicker.MinimumDate = NSDate.Now; dayPicker.MaximumDate = NSDate.Now.AddSeconds (604800); dayPicker.AddTarget (dayPickerChanged, UIControlEvent.AllEvents); dayPicker.Hidden = true; prescriptionLengthLabel = new UILabel (); prescriptionLengthLabel.Text = "Prescription Length"; prescriptionLengthTextField = new UITextField (); prescriptionLengthTextField.Text = "20"; prescriptionLengthTextField.AddTarget (prescriptionTextFieldChanged, UIControlEvent.EditingDidEnd | UIControlEvent.EditingDidEndOnExit); prescriptionLengthTextField.KeyboardType = UIKeyboardType.NumberPad; prescriptionLengthTextField.BorderStyle = UITextBorderStyle.RoundedRect; prescriptionLengthStepper = new UIStepper (); prescriptionLengthStepper.Value = 20; prescriptionLengthStepper.MinimumValue = 1; prescriptionLengthStepper.AddTarget (prescriptionStepperIncremented, UIControlEvent.ValueChanged); prescriptionDayLabel = new UILabel (); prescriptionDayLabel.Text = "Days"; UIStackView prescriptionStackView = new UIStackView (new UIView[] { prescriptionLengthTextField, prescriptionLengthStepper, prescriptionDayLabel }); prescriptionStackView.Axis = UILayoutConstraintAxis.Horizontal; prescriptionStackView.Alignment = UIStackViewAlignment.Leading; prescriptionStackView.Distribution = UIStackViewDistribution.FillProportionally; prescriptionStackView.Spacing = 5; refillsLabel = new UILabel (); refillsLabel.Text = "Refills Remaining"; refillsTextField = new UITextField (); refillsTextField.Text = "0"; refillsTextField.KeyboardType = UIKeyboardType.NumberPad; refillsTextField.BorderStyle = UITextBorderStyle.RoundedRect; refillsTextField.AddTarget (refillsTextFieldChanged, UIControlEvent.EditingDidEnd | UIControlEvent.EditingDidEndOnExit); refillsStepper = new UIStepper (); refillsStepper.Value = 0; refillsStepper.MinimumValue = 0; refillsStepper.AddTarget (refillsStepperIncremented, UIControlEvent.ValueChanged); UIStackView refillsStackView = new UIStackView (new UIView[] { refillsTextField, refillsStepper }); refillsStackView.Spacing = 5; refillsStackView.Alignment = UIStackViewAlignment.Leading; refillsStackView.Distribution = UIStackViewDistribution.FillProportionally; refillsStackView.Axis = UILayoutConstraintAxis.Horizontal; pharmacyTextView = new UITextView (); pharmacyTextView.Text = "Pharmacy Address"; pharmacyTextView.ScrollEnabled = false; pharmacyTextView.BackgroundColor = UIColor.LightGray; pharmacyTextField = new UITextField (); pharmacyTextField.Text = "Pharmacy Address"; pharmacyTextField.BorderStyle = UITextBorderStyle.RoundedRect; // Sets up the stackview stackView.Spacing = 5; stackView.Alignment = UIStackViewAlignment.Leading; stackView.Distribution = UIStackViewDistribution.EqualSpacing; stackView.AddArrangedSubview (nameField); UIView spaceView = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER)); spaceView.AddConstraint (NSLayoutConstraint.Create (spaceView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER)); stackView.AddArrangedSubview (spaceView); stackView.AddArrangedSubview (medTypeLabel); stackView.AddArrangedSubview (medTypeButton); stackView.AddArrangedSubview (medTypePicker); medTypePicker.Hidden = true; UIView spaceView2 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER)); spaceView2.AddConstraint (NSLayoutConstraint.Create (spaceView2, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER)); stackView.AddArrangedSubview (spaceView2); stackView.AddArrangedSubview (freqLabel); stackView.AddArrangedSubview (freqStackView); stackView.AddArrangedSubview (freqButton); stackView.AddArrangedSubview (freqPicker); freqPicker.Hidden = true; UIView spaceView3 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER)); spaceView3.AddConstraint (NSLayoutConstraint.Create (spaceView3, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER)); stackView.AddArrangedSubview (spaceView3); stackView.AddArrangedSubview (timeStack); stackView.AddArrangedSubview (dayLabel); stackView.AddArrangedSubview (dayButton); stackView.AddArrangedSubview (dayPicker); UIView spaceView4 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER)); spaceView4.AddConstraint (NSLayoutConstraint.Create (spaceView4, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER)); stackView.AddArrangedSubview (spaceView4); stackView.AddArrangedSubview (prescriptionLengthLabel); stackView.AddArrangedSubview (prescriptionStackView); UIView spaceView5 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER)); spaceView5.AddConstraint (NSLayoutConstraint.Create (spaceView5, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER)); stackView.AddArrangedSubview (spaceView5); stackView.AddArrangedSubview (refillsLabel); stackView.AddArrangedSubview (refillsStackView); UIView spaceView6 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER)); spaceView6.AddConstraint (NSLayoutConstraint.Create (spaceView6, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER)); stackView.AddArrangedSubview (spaceView6); stackView.AddArrangedSubview (pharmacyTextField); UIView spaceView7 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER)); spaceView7.AddConstraint (NSLayoutConstraint.Create (spaceView7, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER)); stackView.AddArrangedSubview (spaceView7); }
NSLayoutConstraint SetConstant(UIView view, NSLayoutAttribute attr, nfloat value) { var c = NSLayoutConstraint.Create (view, attr, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 0, value); view.AddConstraint (c); return c; }