コード例 #1
0
        private void LayoutView()
        {
            View.BackgroundColor = UIColor.White;
            _amountLabel         = new UILabel();
            _amountLabel.Text    = "Amount: ";
            _amountLabel.Font    = UIFont.PreferredBody;

            _tipPercentageLabel      = new UILabel();
            _tipPercentageLabel.Text = "Tip %: ";
            _tipPercentageLabel.Font = UIFont.PreferredBody;

            _amount = new UITextField
            {
                KeyboardType = UIKeyboardType.DecimalPad,
                Placeholder  = "Total Amount",
                BorderStyle  = UITextBorderStyle.RoundedRect
            };

            _tipPercentage = new UITextField
            {
                KeyboardType = UIKeyboardType.DecimalPad,
                Placeholder  = "Tip %",
                BorderStyle  = UITextBorderStyle.RoundedRect
            };

            _calculateButton = new UIButton(UIButtonType.RoundedRect);
            _calculateButton.SetTitle("Calculate Tip", UIControlState.Normal);
            _tableView          = new UITableView();
            _clearHistoryButton = new UIButton(UIButtonType.RoundedRect);
            _clearHistoryButton.SetTitle("Clear History", UIControlState.Normal);
            _clearHistoryButton.BackgroundColor = UIColor.FromRGB(243, 105, 105);
            _clearHistoryButton.SetTitleColor(UIColor.White, UIControlState.Normal);

            View.Add(_amount);
            View.Add(_tipPercentage);
            View.Add(_calculateButton);
            View.Add(_tableView);
            View.Add(_clearHistoryButton);

            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                _amount.AutoPinEdgeToSuperviewSafeArea(ALEdge.Top, Constants.WideMargin);
                _amount.AutoPinEdgeToSuperviewSafeArea(ALEdge.Left, Constants.DefaultMargin);
            }
            else
            {
                _amount.AutoPinEdgeToSuperviewEdge(ALEdge.Top, Constants.WideMargin);
                _amount.AutoPinEdgeToSuperviewEdge(ALEdge.Left, Constants.DefaultMargin);
            }
            _tipPercentage.AutoPinEdge(ALEdge.Leading, ALEdge.Trailing, _amount, Constants.DefaultMargin);
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                _tipPercentage.AutoPinEdgeToSuperviewSafeArea(ALEdge.Right, Constants.DefaultMargin);
            }
            else
            {
                _tipPercentage.AutoPinEdgeToSuperviewEdge(ALEdge.Right, Constants.DefaultMargin);
            }
            _tipPercentage.AutoAlignAxis(ALAxis.Baseline, _amount);

            _calculateButton.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, _amount, Constants.DefaultMargin);
            _calculateButton.AutoAlignAxisToSuperviewAxis(ALAxis.Vertical);

            _tableView.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, _calculateButton, Constants.WideMargin);
            _tableView.AutoPinEdgeToSuperviewEdge(ALEdge.Leading, Constants.DefaultMargin);
            _tableView.AutoPinEdgeToSuperviewEdge(ALEdge.Trailing, Constants.DefaultMargin);
            _tableView.AutoPinEdge(ALEdge.Bottom, ALEdge.Top, _clearHistoryButton);

            _clearHistoryButton.AutoPinEdgesToSuperviewEdgesExcludingEdge(ALEdge.Top);
            _clearHistoryButton.AutoSetDimension(ALDimension.Height, Constants.WideMargin * 2);
            _clearHistoryButton.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, _tableView);
        }