private RoundButton CreateButton(UIView container, string titleText, UIColor titleColor, UIColor normalFillColor, UIColor hightlightedFillColor) { var button = new RoundButton() { TranslatesAutoresizingMaskIntoConstraints = false, }; button.TitleLabel.Font = UIFont.SystemFontOfSize(17); button.SetTitle(titleText, UIControlState.Normal); button.SetTitleColor(titleColor, UIControlState.Normal); button.SetFillColor(normalFillColor, UIControlState.Normal); button.SetFillColor(hightlightedFillColor, UIControlState.Highlighted); container.AddSubview(button); button.WidthAnchor.ConstraintEqualTo(button.HeightAnchor).Active = true; button.BottomAnchor.ConstraintEqualTo(container.BottomAnchor).Active = true; return(button); }
private UIView BuildTimerView() { var view = new UIView() { //BackgroundColor = UIColor.Cyan, }; _timeLabel = new UILabel() { AdjustsFontSizeToFitWidth = true, Font = UIFont.MonospacedDigitSystemFontOfSize(85, UIFontWeight.Thin), Lines = 1, MinimumScaleFactor = 0.5f, TextAlignment = UITextAlignment.Center, TextColor = UIColor.LightTextColor, TranslatesAutoresizingMaskIntoConstraints = false, }; view.AddSubview(_timeLabel); _timeLabel.TopAnchor.ConstraintEqualTo(view.TopAnchor).Active = true; _timeLabel.BottomAnchor.ConstraintEqualTo(view.BottomAnchor, -60).Active = true; _timeLabel.LeadingAnchor.ConstraintEqualTo(view.LeadingAnchor).Active = true; _timeLabel.TrailingAnchor.ConstraintEqualTo(view.TrailingAnchor).Active = true; _startButton = CreateButton(view, "Start", UIColor.FromRGB(81, 206, 105), UIColor.FromRGB(32, 88, 37), UIColor.FromRGB(24, 52, 31)); _startButton.TrailingAnchor.ConstraintEqualTo(view.TrailingAnchor, -16).Active = true; _stopButton = CreateButton(view, "Stop", UIColor.FromRGB(254, 50, 25), UIColor.FromRGB(88, 38, 31), UIColor.FromRGB(52, 30, 36)); _stopButton.TrailingAnchor.ConstraintEqualTo(view.TrailingAnchor, -16).Active = true; _lapButton = CreateButton(view, "Lap", UIColor.LightTextColor, UIColor.LightGray, UIColor.DarkGray); _lapButton.LeadingAnchor.ConstraintEqualTo(view.LeadingAnchor, 16).Active = true; _resetButton = CreateButton(view, "Reset", UIColor.LightTextColor, UIColor.LightGray, UIColor.DarkGray); _resetButton.LeadingAnchor.ConstraintEqualTo(view.LeadingAnchor, 16).Active = true; _stopButton.WidthAnchor.ConstraintEqualTo(_startButton.WidthAnchor).Active = true; _lapButton.WidthAnchor.ConstraintEqualTo(_startButton.WidthAnchor).Active = true; _resetButton.WidthAnchor.ConstraintEqualTo(_startButton.WidthAnchor).Active = true; _lapButton.SetFillColor(UIColor.FromRGB(21, 21, 21), UIControlState.Disabled); _lapButton.Hidden = false; _lapButton.Enabled = false; _resetButton.Hidden = true; _stopButton.Hidden = true; _startButton.TouchUpInside += StartButton_TouchUpInside; _stopButton.TouchUpInside += StopButton_TouchUpInside; _lapButton.TouchUpInside += LapButton_TouchUpInside; _resetButton.TouchUpInside += ResetButton_TouchUpInside; return(view); }