Esempio n. 1
0
        UIView[] AddAgeControlsToView(UIView overlayView, List <NSLayoutConstraint> constraints)
        {
            UILabel ageTitleLabel = StyleUtilities.CreateStandardLabel();

            ageTitleLabel.Text = "Your age".LocalizedString("The user's age");
            overlayView.AddSubview(ageTitleLabel);

            AgeSlider ageSlider = new AgeSlider {
                Value = person.Age,
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            ageSlider.ValueChanged += OnAgeUpdate;
            overlayView.AddSubview(ageSlider);

            // Display the current age next to the slider
            ageValueLabel = AddAgeValueLabelToView(overlayView);
            UpdateAgeValueLabelFromSlider(ageSlider);

//			// Position the age title and value side by side, within the overlay view
            constraints.Add(NSLayoutConstraint.Create(ageTitleLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Top, 1f, StyleUtilities.ContentVerticalMargin));
            constraints.Add(NSLayoutConstraint.Create(ageTitleLabel, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Leading, 1f, StyleUtilities.ContentHorizontalMargin));
            constraints.Add(NSLayoutConstraint.Create(ageSlider, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ageTitleLabel, NSLayoutAttribute.Trailing, 1f, LabelControlMinimumSpacing));
            constraints.Add(NSLayoutConstraint.Create(ageSlider, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, ageTitleLabel, NSLayoutAttribute.CenterY, 1f, 0f));
            constraints.Add(NSLayoutConstraint.Create(ageValueLabel, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ageSlider, NSLayoutAttribute.Trailing, 1f, LabelControlMinimumSpacing));
            constraints.Add(NSLayoutConstraint.Create(ageValueLabel, NSLayoutAttribute.FirstBaseline, NSLayoutRelation.Equal, ageTitleLabel, NSLayoutAttribute.FirstBaseline, 1f, 0f));
            constraints.Add(NSLayoutConstraint.Create(ageValueLabel, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Trailing, 1f, -1 * StyleUtilities.ContentHorizontalMargin));

            return(new UIView[] { ageTitleLabel, ageSlider, ageValueLabel });
        }
Esempio n. 2
0
        void UpdateAgeValueLabelFromSlider(AgeSlider ageSlider)
        {
            NSNumber number = NSNumber.FromFloat(ageSlider.Value);

            ageValueLabel.Text = NSNumberFormatter.LocalizedStringFromNumbernumberStyle(number, NSNumberFormatterStyle.Decimal);
        }
		private void UpdateAgeValueLabelFromSlider(AgeSlider ageSlider)
		{
			NSNumber number = NSNumber.FromFloat (ageSlider.Value);
			_ageValueLabel.Text = NSNumberFormatter.LocalizedStringFromNumbernumberStyle (number, NSNumberFormatterStyle.Decimal);
		}
		private UIView[] AddAgeControlsToView(UIView overlayView, List<NSLayoutConstraint> constraints)
		{
			UILabel ageTitleLabel = StyleUtilities.CreateStandardLabel ();
			ageTitleLabel.Text = "Your age".LocalizedString ("The user's age");
			overlayView.AddSubview (ageTitleLabel);

			AgeSlider ageSlider = new AgeSlider {
				Value = _person.Age,
				TranslatesAutoresizingMaskIntoConstraints = false,
			};
			ageSlider.ValueChanged += OnAgeUpdate;
			overlayView.AddSubview (ageSlider);

			// Display the current age next to the slider
			_ageValueLabel = AddAgeValueLabelToView (overlayView);
			UpdateAgeValueLabelFromSlider (ageSlider);

//			// Position the age title and value side by side, within the overlay view
			constraints.Add (NSLayoutConstraint.Create (ageTitleLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Top, 1f, StyleUtilities.ContentVerticalMargin));
			constraints.Add (NSLayoutConstraint.Create (ageTitleLabel, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Leading, 1f, StyleUtilities.ContentHorizontalMargin));
			constraints.Add (NSLayoutConstraint.Create (ageSlider, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ageTitleLabel, NSLayoutAttribute.Trailing, 1f, LabelControlMinimumSpacing));
			constraints.Add (NSLayoutConstraint.Create (ageSlider, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, ageTitleLabel, NSLayoutAttribute.CenterY, 1f, 0f));
			constraints.Add (NSLayoutConstraint.Create (_ageValueLabel, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ageSlider, NSLayoutAttribute.Trailing, 1f, LabelControlMinimumSpacing));
			constraints.Add (NSLayoutConstraint.Create (_ageValueLabel, NSLayoutAttribute.FirstBaseline, NSLayoutRelation.Equal, ageTitleLabel, NSLayoutAttribute.FirstBaseline, 1f, 0f));
			constraints.Add (NSLayoutConstraint.Create (_ageValueLabel, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Trailing, 1f, -1 * StyleUtilities.ContentHorizontalMargin));

			return new UIView[]{ ageTitleLabel, ageSlider, _ageValueLabel };
		}