Beispiel #1
0
        public override void LayoutSubviews()
        {
            if (_shadowView != null)
            {
                if (_shadowView.Superview == null)
                {
                    Superview.InsertSubviewBelow(_shadowView, this);
                }

                _shadowView?.SetNeedsLayout();
            }
            base.LayoutSubviews();
        }
        private void InsertSubview(UIView view)
        {
            Superview.InsertSubviewBelow(view, this);

            var verticalConstraint = NSLayoutConstraint.Create(this, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal,
                                                               view, NSLayoutAttribute.CenterY, 1, 0);
            var leadingConstraint = NSLayoutConstraint.Create(this, NSLayoutAttribute.Leading, NSLayoutRelation.Equal,
                                                              view, NSLayoutAttribute.Leading, 1, 0);
            var trailingConstraint = NSLayoutConstraint.Create(this, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal,
                                                               view, NSLayoutAttribute.Trailing, 1, 0);

            Superview.AddConstraints(new[] { verticalConstraint, leadingConstraint, trailingConstraint });
        }
Beispiel #3
0
        public override void MovedToSuperview()
        {
            if (_shadowLayer != null)
            {
                return;
            }

            _shadowLayer = new UIView {
                BackgroundColor = UIColor.Red
            };
            _shadowLayer.Layer.ShadowColor        = UIColor.DarkGray.CGColor;
            _shadowLayer.Layer.ShadowOffset       = new CGSize(0.0f, 1f);
            _shadowLayer.Layer.ShadowOpacity      = 1f;
            _shadowLayer.Layer.ShadowRadius       = _requestedElevation < 0f ? 3f:_requestedElevation;
            _shadowLayer.Layer.MasksToBounds      = false;
            _shadowLayer.Layer.ShouldRasterize    = true;
            _shadowLayer.Layer.RasterizationScale = UIScreen.MainScreen.Scale;
            Superview.InsertSubviewBelow(_shadowLayer, this);
        }
        private void initialize()
        {
            //Make new tableview and do some settings
            AutoCompleteTableView = new UITableView();
            AutoCompleteTableView.Layer.CornerRadius = 5;                                                                    //rounded corners
            AutoCompleteTableView.ContentInset       = UIEdgeInsets.Zero;
            AutoCompleteTableView.AutoresizingMask   = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; //for resizing (switching from table to portait for example)
            AutoCompleteTableView.Bounces            = false;
            AutoCompleteTableView.BackgroundColor    = UIColor.Clear;
            AutoCompleteTableView.TranslatesAutoresizingMaskIntoConstraints = false;
            AutoCompleteTableView.Source          = this.AutoCompleteViewSource;
            AutoCompleteTableView.TableFooterView = new UIView();
            AutoCompleteTableView.Hidden          = true;

            //Some textfield settings
            this.TranslatesAutoresizingMaskIntoConstraints = false;
            this.Delegate           = this;
            this.AutocorrectionType = UITextAutocorrectionType.No;
            this.ClearButtonMode    = UITextFieldViewMode.WhileEditing;

            var isTableViewController = _parentTableViewController ?? (_parentViewController as UITableViewController);

            //if parent is tableviewcontroller
            if (isTableViewController != null)
            {
                _parentIsUITableViewController = true;
                if (_parentTableViewController == null)
                {
                    _parentTableViewController = isTableViewController;
                }
                _parentTableViewBounces         = _parentTableViewController.TableView.Bounces;
                _parentTableViewAllowsSelection = _parentTableViewController.TableView.AllowsSelection;

                //Add the view to the contentview of the cell
                Superview.AddSubview(AutoCompleteTableView);

                UITableViewCell cell = Superview.Superview as UIKit.UITableViewCell;

                //Get indexpath to set the constraint to the right cell
                NSIndexPath indexPath = _parentTableViewController.TableView.IndexPathForCell(cell);

                if (indexPath == null)
                {
                    Console.WriteLine("Should be initialized in the ViewDidAppear and not in the ViewDidLoad!");
                    return;
                }
                //add constraints
                Superview.AddConstraints(
                    AutoCompleteTableView.WithSameCenterY(this).Plus((AutocompleteTableViewHeight / 2) + 10 + cell.Frame.Height * indexPath.Row),
                    AutoCompleteTableView.WithSameWidth(this),
                    AutoCompleteTableView.WithSameLeft(this),
                    AutoCompleteTableView.Height().EqualTo(AutocompleteTableViewHeight)
                    );
            }
            else
            {
                Superview.InsertSubviewBelow(AutoCompleteTableView, _parentViewController.View);

                //add constraints
                Superview.AddConstraints(
                    AutoCompleteTableView.AtTopOf(this, this.Frame.Height - 5),
                    AutoCompleteTableView.WithSameWidth(this),
                    AutoCompleteTableView.WithSameLeft(this),
                    AutoCompleteTableView.Height().EqualTo(AutocompleteTableViewHeight)
                    );
            }

            //listen to edit events
            this.EditingChanged += async(sender, eventargs) =>
            {
                if (this.Text.Length > StartAutoCompleteAfterTicks)
                {
                    showAutoCompleteView();
                    await UpdateTableViewData();
                }
            };

            this.EditingDidEnd += (sender, eventargs) =>
            {
                hideAutoCompleteView();
            };
        }