public override UICollectionViewCell GetCell(UICollectionView collectionView, Foundation.NSIndexPath indexPath)
        {
            UICollectionViewCell cell = collectionView.DequeueReusableCell(cellIdentifier, indexPath) as UICollectionViewCell;

            cell.Layer.BorderColor = UIColor.Black.CGColor;
            cell.Layer.BorderWidth = 0.5f;

            foreach (var lbl in cell.Subviews)
            {
                if (lbl.GetType() == typeof(UILabel))
                {
                    lbl.RemoveFromSuperview();
                }
            }

            UILabel label = new UILabel(new CoreGraphics.CGRect(5, 30, 90, 60));

            label.Font            = UIFont.FromName("Helvetica", 10f);
            label.BackgroundColor = UIColor.Clear;
            label.TextAlignment   = UITextAlignment.Left;
            label.Lines           = 2;
            label.Text            = documentsList [indexPath.Row].documentDisplayName;
            cell.AddSubview(label);

            UIImageView imageView = new UIImageView(new CoreGraphics.CGRect(5, 5, 25, 25));

            imageView.Image = new UIImage("pdfImage");
            cell.AddSubview(imageView);

            return(cell);
        }
Exemple #2
0
        /// <summary>
        /// Creates the cells and adds them to grid.
        /// Creates the buttons and adds them to cell.
        /// Creates the image from img path and adds them to button.
        /// </summary>
        public void CreateCells()
        {
            //gets the starting index for button ids using page and number of buttons per page
            nint btnIdCounter = (PageNum - 1) * AppData.ButtonsPerPage;

            for (int c = 0; c < Cols; c++)
            {
                for (int r = 0; r < Rows; r++)
                {
                    //create cell
                    CGRect cellFrame          = new CGRect(c * CellW, r * CellH, CellW, CellH);
                    UICollectionViewCell cell = new UICollectionViewCell(cellFrame);
                    Grid.AddSubview(cell); //add cell to grid

                    //create button and button data
                    ButtonData   theButtonData;
                    CustomButton theButton = new CustomButton();
                    CGRect       btnFrame  = new CGRect(0 + (ButtonPadding / 2), 0 + (ButtonPadding / 2), CellW - (ButtonPadding), CellH - (ButtonPadding));

                    //retrives button data obj from list of buttons using id
                    //returns null if no match
                    theButtonData = AppData.Buttons.Find((x) =>
                    {
                        return(x.ID == btnIdCounter);
                    });

                    //if no button data obj existed with the button id
                    if (theButtonData == null) //create default button data
                    {
                        //set the button data default values
                        theButtonData              = new ButtonData();
                        theButtonData.ID           = (int)btnIdCounter;
                        theButtonData.BorderColour = new BorderColourData()
                        {
                            Red = 0, Green = 0, Blue = 105
                        };
                        theButtonData.VidPath = "babyshark.m4v";
                        //theButtonData.ImgPath = "shark.jpg";
                        theButtonData.ImgPath = "defaultbuttonimg.png";
                    }

                    //fill the button with the button data properties
                    theButton.ID           = (int)theButtonData.ID;
                    theButton.BorderColour = UIColor.FromRGB(theButtonData.BorderColour.Red, theButtonData.BorderColour.Green, theButtonData.BorderColour.Blue).CGColor;
                    theButton.VidPath      = theButtonData.VidPath;
                    theButton.ImgPath      = theButtonData.ImgPath;
                    //set the button styling and settings
                    theButton.Layer.BorderColor = theButton.BorderColour;

                    //set constant properties for every button
                    theButton.Frame = btnFrame;
                    //theButton.Layer.BorderWidth = ButtonBorderW;
                    theButton.Layer.BorderWidth  = AppData.BorderWidth;
                    theButton.Layer.CornerRadius = ButtonCornerRadius;

                    //
                    var maskingShapeLayer = new CAShapeLayer()
                    {
                        Path = UIBezierPath.FromRoundedRect(theButton.Bounds, UIRectCorner.AllCorners, new CGSize(26, 26)).CGPath
                    };
                    theButton.Layer.Mask = maskingShapeLayer;

                    //add play vid function to button click
                    theButton.TouchUpInside -= ButtonClickPlayVid; //fixes a saved button playing multiple times!
                    theButton.TouchUpInside += ButtonClickPlayVid;

                    //add button to cell
                    cell.AddSubview(theButton);

                    //create img
                    CGRect      imgFrame = new CGRect(0, 0, theButton.Bounds.Width, theButton.Bounds.Height);
                    UIImageView img      = new UIImageView(imgFrame);
                    img.Image = new UIImage(theButton.ImgPath); //set the image to the button img path
                    img.UserInteractionEnabled = false;         //So user can still click the button
                    img.Layer.CornerRadius     = ButtonCornerRadius;
                    img.ClipsToBounds          = true;          //enables corner radius on img

                    //add img to button
                    theButton.AddSubview(img);

                    btnIdCounter++; //increments the button id counter for the next button
                }
            }
        }