Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Test.RoundedRectView"/> class.
 /// </summary>
 /// <param name='rect'>Rectangle of the view</param>
 /// <param name='oBackgroundColor'>background color</param>
 /// <param name='eCornerFlags'>rounded corners</param>
 public RoundedRectView(RectangleF rect, UIColor oBackgroundColor, UIRectCorner eCornerFlags) : base(rect)
 {
     this.fCornerRadius   = 25f;
     this.eRoundedCorners = eCornerFlags;
     this.BackgroundColor = oBackgroundColor;
     this.UpdateMask();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Test.RoundedRectView"/> class.
 /// </summary>
 /// <param name='rect'>rectangle of the view</param>
 public RoundedRectView(RectangleF rect)
     : base(rect)
 {
     this.fCornerRadius = 25f;
     this.eRoundedCorners = UIRectCorner.AllCorners;
     this.UpdateMask ();
 }
Example #3
0
        private UIRectCorner GetCornerPosition(UIRectCorner corner, bool shouldAppend)
        {
            var val = corner;

            if (RoundedCornerEffect.HasTopLeft(this.Element))
            {
                val = shouldAppend ? val | UIRectCorner.TopLeft : UIRectCorner.TopLeft;
            }

            if (RoundedCornerEffect.HasTopRight(this.Element))
            {
                val = shouldAppend ? val | UIRectCorner.TopRight : UIRectCorner.TopRight;
            }

            if (RoundedCornerEffect.HasBottomLeft(this.Element))
            {
                val = shouldAppend ? val | UIRectCorner.BottomLeft : UIRectCorner.BottomLeft;
            }

            if (RoundedCornerEffect.HasBottomRight(this.Element))
            {
                val = shouldAppend ? val | UIRectCorner.BottomRight : UIRectCorner.BottomRight;
            }

            return(val);
        }
Example #4
0
        /// <summary>
        /// Rounds off the corners of the view.
        /// </summary>
        /// <param name="corners">Which corners to affect</param>
        /// <param name="cornerRadius">Radius of curve</param>
        public static void MakeRoundedCorners(this UIView view, UIRectCorner corners, float cornerRadius)
        {
            CAShapeLayer maskLayer = new CAShapeLayer();

            maskLayer.Path  = UIBezierPath.FromRoundedRect(view.Bounds, corners, new CGSize(cornerRadius, cornerRadius)).CGPath;
            view.Layer.Mask = maskLayer;
        }
Example #5
0
		/// <summary>
		/// Initializes a new instance of the <see cref="RoundedRectView"/> class.
		/// </summary>
		/// <param name='rect'>Rectangle of the view</param>
		/// <param name='oBackgroundColor'>background color</param>
		/// <param name='eCornerFlags'>rounded corners</param>
		public RoundedRectView (RectangleF rect, UIColor oBackgroundColor, UIRectCorner eCornerFlags) : base(rect)
		{
			this.fCornerRadius = CORNER_RADIUS;
			this.eRoundedCorners = eCornerFlags;
			this.BackgroundColor = oBackgroundColor;
			this.UpdateMask();
		}
Example #6
0
        public override void Draw(CGRect rect)
        {
            var view = (RoundedCornerStackLayout)Element;

            UIRectCorner corners = 0;

            if (view.RoundedCorners.ToLower().Contains("topleft"))
            {
                corners = corners | UIRectCorner.TopLeft;
            }

            if (view.RoundedCorners.ToLower().Contains("topright"))
            {
                corners = corners | UIRectCorner.TopRight;
            }

            if (view.RoundedCorners.ToLower().Contains("bottomright"))
            {
                corners = corners | UIRectCorner.BottomRight;
            }

            if (view.RoundedCorners.ToLower().Contains("bottomleft"))
            {
                corners = corners | UIRectCorner.BottomLeft;
            }

            if (view.RoundedCorners.ToLower().Contains("all"))
            {
                corners = UIRectCorner.AllCorners;
            }
            var radius = view.CornerRadius;

            if (radius == -1)
            {
                radius = (float)view.Width / 16;
            }
            var mPath = UIBezierPath.FromRoundedRect(Layer.Bounds, corners, new CGSize(radius, radius)).CGPath;


            Layer.ShadowColor   = view.ShadowColor.ToCGColor();
            Layer.ShadowOffset  = new CGSize(view.HorizontalShadowOffset, view.VerticalShadowOffset);
            Layer.ShadowOpacity = view.ShadowOpacity;
            Layer.ShadowRadius  = view.ShadowRadius;


            if (Layer.Sublayers == null || Layer.Sublayers.Length <= 0)
            {
                return;
            }

            var subLayer = this.Layer.Sublayers[0];

            subLayer.CornerRadius = (float)radius;
            subLayer.Mask         = new CAShapeLayer
            {
                Frame = Layer.Bounds,
                Path  = mPath,
            };
        }
Example #7
0
        public static void RoundCorners(this UIView view, UIRectCorner corners, nfloat radius)
        {
            var path = UIBezierPath.FromRoundedRect(view.Bounds, corners, new CGSize(radius, radius));

            view.Layer.Mask = new CAShapeLayer {
                Path = path.CGPath
            };
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Test.RoundedRectView"/> class.
 /// </summary>
 /// <param name='rect'>Rectangle of the view</param>
 /// <param name='oBackgroundColor'>background color</param>
 public RoundedRectView(RectangleF rect, UIColor oBackgroundColor)
     : base(rect)
 {
     this.fCornerRadius = 25f;
     this.eRoundedCorners = UIRectCorner.AllCorners;
     this.BackgroundColor = oBackgroundColor;
     this.UpdateMask ();
 }
        private void ClipCorners()
        {
            var view = (ButtonRound)this.Element;

            Control.ClipsToBounds = true;

            CAShapeLayer maskLayer = new CAShapeLayer();

            UIRectCorner corners = UIRectCorner.AllCorners;

            if (view.IsRoundedLeftCorners && !view.IsRoundedRightCorners)
            {
                corners = UIRectCorner.BottomLeft | UIRectCorner.TopLeft;
            }
            else if (view.IsRoundedRightCorners && !view.IsRoundedLeftCorners)
            {
                corners = UIRectCorner.BottomRight | UIRectCorner.TopRight;
            }

            UIBezierPath cropPath = UIBezierPath.FromRoundedRect(Control.Bounds, corners, new CGSize(view.CornerRadius, view.CornerRadius));

            maskLayer.Frame             = Control.Bounds;
            maskLayer.Path              = cropPath.CGPath;
            Control.Layer.Mask          = maskLayer;
            Control.Layer.MasksToBounds = true;

            if (view.BackgroundColor == Color.Transparent ||
                view.BackgroundColor == Color.White)
            {
                bool reuseExistingSublayer = false;
                foreach (CALayer layer in Control?.Layer.Sublayers)
                {
                    if (layer is CAShapeLayer)
                    {
                        ((CAShapeLayer)layer).Path        = maskLayer.Path;
                        ((CAShapeLayer)layer).FillColor   = Color.Transparent.ToCGColor();
                        ((CAShapeLayer)layer).StrokeColor = view.BorderColor.ToCGColor();
                        ((CAShapeLayer)layer).LineWidth   = 2;
                        ((CAShapeLayer)layer).Frame       = Control.Bounds;

                        reuseExistingSublayer = true;
                    }
                }

                if (!reuseExistingSublayer)
                {
                    CAShapeLayer borderLayer = new CAShapeLayer();
                    borderLayer.Path        = maskLayer.Path;
                    borderLayer.FillColor   = Color.Transparent.ToCGColor();
                    borderLayer.StrokeColor = view.BorderColor.ToCGColor();
                    borderLayer.LineWidth   = 2;
                    borderLayer.Frame       = Control.Bounds;

                    Control.Layer.AddSublayer(borderLayer);
                }
            }
        }
Example #10
0
        public override void Draw(CGRect rect)
        {
            var view = (eliteElements.eliteVideo)Element;

            UIRectCorner corners = 0;

            if (view.CornerRounded.ToLower().Contains("topleft"))
            {
                corners = corners | UIRectCorner.TopLeft;
            }

            if (view.CornerRounded.ToLower().Contains("topright"))
            {
                corners = corners | UIRectCorner.TopRight;
            }

            if (view.CornerRounded.ToLower().Contains("bottomright"))
            {
                corners = corners | UIRectCorner.BottomRight;
            }

            if (view.CornerRounded.ToLower().Contains("bottomleft"))
            {
                corners = corners | UIRectCorner.BottomLeft;
            }

            if (view.CornerRounded.ToLower().Contains("all"))
            {
                corners = UIRectCorner.AllCorners;
            }

            var mPath = UIBezierPath.FromRoundedRect(Layer.Bounds, corners, new CGSize(view.CornerRadius, view.CornerRadius)).CGPath;

            if (view.IsPopup)
            {
                Layer.ShadowColor   = view.ShadowColor.ToCGColor();
                Layer.ShadowOffset  = new CGSize(view.ShadowHorizontalOffset, view.ShadowVerticalOffset);
                Layer.ShadowOpacity = view.ShadowOpacity;
                Layer.ShadowRadius  = view.ShadowRadius;
            }

            if (Layer.Sublayers == null || Layer.Sublayers.Length <= 0)
            {
                return;
            }

            var subLayer = this.Layer.Sublayers[0];

            subLayer.CornerRadius = (float)view.CornerRadius;
            subLayer.Mask         = new CAShapeLayer
            {
                Frame = Layer.Bounds,
                Path  = mPath
            };
            subLayer.BorderColor = view.BorderColor.ToCGColor();
            subLayer.BorderWidth = view.BorderThickness;
        }
        public static void SetCornerRadius(this UIView view, CGSize radii, UIRectCorner corners)
        {
            var rounded = UIBezierPath.FromRoundedRect(view.Bounds, corners, radii);
            var shape   = new CAShapeLayer {
                Path = rounded.CGPath
            };

            view.Layer.Mask          = shape;
            view.Layer.MasksToBounds = true;
        }
Example #12
0
        private void UpdateButtonBorders()
        {
            for (int i = 0; i < this.buttonRows.Count; i++)
            {
                bool isFirstRow = i == 0;
                bool isLastRow  = i == this.buttonRows.Count - 1;

                IEnumerable <UIButton> buttonsForRow = this.buttonRows[i].Subviews.Cast <UIButton>();

                int buttonsInRow = buttonsForRow.Count();
                for (int j = 0; j < buttonsInRow; j++)
                {
                    UIButton button = buttonsForRow.ElementAt(j);
                    button.LayoutIfNeeded();

                    UIRectCorner corners       = 0;
                    bool         isFirstColumn = j == 0;
                    bool         isLastColumn  = j == buttonsInRow - 1;

                    if (isFirstRow)
                    {
                        if (isFirstColumn)
                        {
                            corners |= UIRectCorner.TopLeft;
                        }

                        if (isLastColumn)
                        {
                            corners |= UIRectCorner.TopRight;
                        }
                    }

                    if (isLastRow)
                    {
                        if (isFirstColumn)
                        {
                            corners |= UIRectCorner.BottomLeft;
                        }

                        if (isLastColumn)
                        {
                            corners |= UIRectCorner.BottomRight;
                        }
                    }

                    this.UpdateButtonBorder(
                        button,
                        corners,
                        isFirstRow,
                        isLastRow,
                        isFirstColumn,
                        isLastColumn);
                }
            }
        }
Example #13
0
        /// <summary>
        /// Rounds the corners.
        /// </summary>
        /// <param name="view">current view</param>
        /// <param name="corners">corners enums</param>
        /// <param name="size">size of rounded corners</param>
        internal static void RoundCorners(this UIView view, UIRectCorner corners, int size)
        {
            view.Layer.Mask = null;
            var bounds    = view.Bounds;
            var mask      = UIBezierPath.FromRoundedRect(bounds, corners, new CGSize(size, size));
            var maskLayer = new CAShapeLayer();

            maskLayer.Frame = bounds;
            maskLayer.Path  = mask.CGPath;
            view.Layer.Mask = maskLayer;
        }
Example #14
0
        public static void SetViewConnerRadius(this UIView view, UIRectCorner conners, CGSize sizes)
        {
            var maskPath = UIBezierPath.FromRoundedRect(view.Bounds, conners, sizes);

            var maskLayer = new CAShapeLayer();

            maskLayer.Path  = maskPath.CGPath;
            maskLayer.Frame = view.Bounds;

            view.Layer.Mask = maskLayer;
        }
Example #15
0
        /// <summary>
        ///     Use it in LayoutSubviews method.
        /// </summary>
        /// <param name="view">Target view.</param>
        /// <param name="corners">Corners.</param>
        /// <param name="radius">Radius.</param>
        public static void WithCornerRadius(this UIView view, UIRectCorner corners, float radius)
        {
            view.ClipsToBounds = true;
            var path      = UIBezierPath.FromRoundedRect(view.Bounds, corners, new CGSize(radius, radius));
            var maskLayer = new CAShapeLayer
            {
                Path = path.CGPath
            };

            view.Layer.Mask = maskLayer;
        }
        /// <summary>
        /// Rounds 1 to 4 corners of a view.
        /// </summary>
        /// <param name="view">The view to apply the rounding to.</param>
        /// <param name="corners">The corners to round</param>
        /// <param name="radii">The size of the border radius.</param>
        public static void RoundCorners(this UIView view, UIRectCorner corners, CGSize radii)
        {
            view.Layer.CornerRadius = 0;
            var shapePath = UIBezierPath.FromRoundedRect(view.Bounds, corners, radii);

            using (var cornerLayer = new CAShapeLayer())
            {
                cornerLayer.Frame = view.Bounds;
                cornerLayer.Path  = shapePath.CGPath;
                view.Layer.Mask   = cornerLayer;
            }
        }
Example #17
0
        public void roundCorners(UIRectCorner corners, nfloat width, nfloat height)
        {
            UIBezierPath path = UIBezierPath.FromRoundedRect(this.Bounds, corners, new CoreGraphics.CGSize(width, height));

            CAShapeLayer maskLayer = new CAShapeLayer();

            maskLayer.Frame = this.Bounds;

            maskLayer.Path = path.CGPath;

            this.Layer.Mask = maskLayer;
        }
        public override void Draw(CoreGraphics.CGRect rect)
        {
            base.Draw(rect);
            this.LayoutIfNeeded();

            var          control      = (RoundedCornerView)Element;
            UIRectCorner uIRectCorner = 0;

            if (control != null)
            {
                if (control.TopLeft)
                {
                    uIRectCorner |= UIRectCorner.TopLeft;
                }
                if (control.TopRight)
                {
                    uIRectCorner |= UIRectCorner.TopRight;
                }
                if (control.BottomLeft)
                {
                    uIRectCorner |= UIRectCorner.BottomRight;
                }
                if (control.BottomRight)
                {
                    uIRectCorner |= UIRectCorner.BottomLeft;
                }

                if (!control.BottomLeft && !control.BottomRight && !control.TopLeft && !control.TopRight)
                {
                    uIRectCorner = UIRectCorner.AllCorners;
                }

                nfloat radius            = control.CornerRadius;
                var    maskingShapeLayer = new CAShapeLayer
                {
                    Path = UIBezierPath.FromRoundedRect(Bounds, uIRectCorner, new CGSize(radius, radius)).CGPath
                };
                Layer.Mask = maskingShapeLayer;

                this.ClipsToBounds       = true;
                this.Layer.MasksToBounds = true;
                this.Layer.BorderWidth   = control.BorderWidth;

                if (control.BorderWidth > 0)
                {
                    control.Padding        = new Thickness(control.BorderWidth);
                    this.Layer.BorderColor = control.BorderColor.ToCGColor();
                }
            }
        }
        protected virtual void SetCornerRadius(MvvmAspire.Controls.Button element)
        {
            if (element.Corner != 0)
            {
                int          radius     = 0;
                UIRectCorner forCorners = 0;

                if (element.Corner.Bottom > 0 &&
                    element.Corner.Left > 0 &&
                    element.Corner.Right > 0 &&
                    element.Corner.Top > 0)
                {
                    forCorners = UIRectCorner.AllCorners;
                    radius     = Convert.ToInt32(element.Corner.Top);
                }
                else
                {
                    if (element.Corner.Bottom > 0)
                    {
                        forCorners = forCorners | UIRectCorner.BottomRight;
                        radius     = Convert.ToInt32(element.Corner.Bottom);
                    }
                    if (element.Corner.Left > 0)
                    {
                        forCorners = forCorners | UIRectCorner.BottomLeft;
                        radius     = Convert.ToInt32(element.Corner.Left);
                    }
                    if (element.Corner.Right > 0)
                    {
                        forCorners = forCorners | UIRectCorner.TopRight;
                        radius     = Convert.ToInt32(element.Corner.Right);
                    }
                    if (element.Corner.Top > 0)
                    {
                        forCorners = forCorners | UIRectCorner.TopLeft;
                        radius     = Convert.ToInt32(element.Corner.Top);
                    }
                }

                Control.SetCornerRadius(radius, forCorners);
                Control.Layer.MasksToBounds = true;
                Control.ClipsToBounds       = true;
            }
            else
            {
                Control.SetCornerRadius(0, UIRectCorner.AllCorners);
                Control.ClipsToBounds = true;
            }
        }
Example #20
0
 public static void SetCornerRadius(this UIView view, System.nfloat radius, UIRectCorner forCorners)
 {
     if (forCorners == UIRectCorner.AllCorners)
     {
         view.Layer.CornerRadius = radius;
         view.Layer.Mask         = null;
     }
     else
     {
         UIBezierPath maskPath  = UIBezierPath.FromRoundedRect(view.Bounds, forCorners, new CGSize(radius, radius));
         CAShapeLayer maskLayer = new CAShapeLayer();
         maskLayer.Frame = view.Bounds;
         maskLayer.Path  = maskPath.CGPath;
         view.Layer.Mask = maskLayer;
     }
 }
Example #21
0
 public static void ApplyCornerRadius(UIView currentView, UIRectCorner radiusCorners, bool remove = false, int radius = 4)
 {
     if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
     {
         currentView.Layer.MaskedCorners = radiusCorners.ToCornerMask();
         currentView.Layer.CornerRadius  = radius;
     }
     else
     {
         UIBezierPath maskPath  = UIBezierPath.FromRoundedRect(currentView.Bounds, radiusCorners, remove ? new CGSize(0, 0) : new CGSize(radius, radius));
         CAShapeLayer maskLayer = new CAShapeLayer();
         maskLayer.Frame        = currentView.Bounds;
         maskLayer.Path         = maskPath.CGPath;
         currentView.Layer.Mask = maskLayer;
     }
 }
Example #22
0
        public static void ApplyBorder(this UIView currentView, UIRectCorner radiusCorners, int radius = 0, UIColor color = null, float lineWidth = 1f)
        {
            var col = color == null?UIColor.FromRGB(61, 71, 82).CGColor : color.CGColor;

            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                currentView.Layer.MaskedCorners = radiusCorners.ToCornerMask();
                currentView.Layer.CornerRadius  = radius;
                currentView.Layer.BorderWidth   = lineWidth;
                currentView.Layer.BorderColor   = col;
            }
            else
            {
                UIBezierPath maskPath = UIBezierPath.FromRoundedRect(currentView.Bounds, radiusCorners, new CGSize(radius, radius));
                ApplyBorder(maskPath, currentView, col, lineWidth);
            }
        }
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            if (Element == null || !Element.BottomLeft && !Element.BottomRight && !Element.TopLeft && !Element.TopRight)
            {
                return;
            }

            UIRectCorner uIRectCorner = 0;

            if (Element.BottomLeft)
            {
                uIRectCorner |= UIRectCorner.BottomLeft;
            }
            if (Element.TopLeft)
            {
                uIRectCorner |= UIRectCorner.TopLeft;
            }
            if (Element.TopRight)
            {
                uIRectCorner |= UIRectCorner.TopRight;
            }
            if (Element.BottomRight)
            {
                uIRectCorner |= UIRectCorner.BottomRight;
            }

            nfloat radius            = (nfloat)Element.RoundedCornerRadius;
            var    maskingShapeLayer = new CAShapeLayer
            {
                Path = UIBezierPath.FromRoundedRect(Bounds, uIRectCorner, new CGSize(radius, radius)).CGPath
            };

            Layer.Mask = maskingShapeLayer;

            if (Element.BorderWidth > 0)
            {
                Layer.BorderWidth = Element.BorderWidth;
                Element.Padding   = new Thickness(Element.BorderWidth);
                Layer.BorderColor = Element.BorderColor.ToCGColor();
            }
        }
Example #24
0
        public static CACornerMask ToCornerMask(this UIRectCorner corner)
        {
            CACornerMask mask = 0;

            if (corner.Has(UIRectCorner.AllCorners) || corner.Has(UIRectCorner.TopLeft))
            {
                mask |= CACornerMask.MinXMinYCorner;
            }
            if (corner.Has(UIRectCorner.AllCorners) || corner.Has(UIRectCorner.TopRight))
            {
                mask |= CACornerMask.MaxXMinYCorner;
            }
            if (corner.Has(UIRectCorner.AllCorners) || corner.Has(UIRectCorner.BottomLeft))
            {
                mask |= CACornerMask.MinXMaxYCorner;
            }
            if (corner.Has(UIRectCorner.AllCorners) || corner.Has(UIRectCorner.BottomRight))
            {
                mask |= CACornerMask.MaxXMaxYCorner;
            }

            return(mask);
        }
Example #25
0
 public RoundedCornerTextfield(UIColor backgroundColor, UIRectCorner cornerFlags) : base(backgroundColor)
 {
     cornerRadius   = CornerRadius;
     roundedCorners = cornerFlags;
 }
Example #26
0
 public RoundedCornerTextfield(UIColor backgroundColor) : base(backgroundColor)
 {
     cornerRadius   = CornerRadius;
     roundedCorners = UIRectCorner.AllCorners;
 }
Example #27
0
 public RoundedCornerTextfield() : base(UIColor.White)
 {
     cornerRadius   = CornerRadius;
     roundedCorners = UIRectCorner.AllCorners;
 }
Example #28
0
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            var cell = base.GetCell(tableView, indexPath);

            cell.Frame                       = cell.ContentView.Frame.SetHeight(tableView.RowHeight);
            cell.ContentView.Frame           = cell.ContentView.Frame.SetHeight(tableView.RowHeight);
            cell.ContentView.BackgroundColor = UIColor.Clear;
            cell.BackgroundColor             = UIColor.Clear;
            cell.IndentationLevel            = 1;

            if (_willBeContainedInOtherView)
            {
                var cellWidth = UIScreen.MainScreen.Bounds.Width - 2 * 8;
                cell.Frame             = cell.ContentView.Frame.SetWidth(cellWidth);
                cell.ContentView.Frame = cell.ContentView.Frame.SetWidth(cellWidth);


                UIRectCorner cornerPlace = 0;
                var          borders     = Border.Right | Border.Left | Border.Bottom;

                //first and last cells have different rounded corners
                if (indexPath.Section == 0 &&
                    indexPath.Row == 0)
                {
                    cornerPlace = UIRectCorner.TopLeft | UIRectCorner.TopRight;
                }

                if (indexPath.Row == tableView.NumberOfRowsInSection(indexPath.Section) - 1)
                {
                    cornerPlace = UIRectCorner.BottomLeft | UIRectCorner.BottomRight;
                }

                //the one before the last: remove the bottom border already present in the cell below
                if (indexPath.Row == tableView.NumberOfRowsInSection(indexPath.Section) - 2)
                {
                    borders = borders ^ Border.Bottom;
                }

                var view = new RoundedCornerView();
                view.Borders   = borders;
                view.Corners   = cornerPlace;
                view.BackColor = UIColor.White;
                view.FirstRowOfTwoRowsTable = indexPath.Row == 0 && tableView.NumberOfRowsInSection(indexPath.Section) == 2;

                view.Frame = new CGRect(0, 0, cellWidth, tableView.RowHeight);
                var container = new UIView {
                    BackgroundColor = UIColor.Clear
                };
                container.AddSubview(view);
                cell.BackgroundView = container;
                cell.SeparatorInset = new UIEdgeInsets(9, 9, 9, 9);
            }
            else
            {
                var cellWidth = UIScreen.MainScreen.Bounds.Width;
                cell.Frame                  = cell.ContentView.Frame.SetWidth(cellWidth);
                cell.ContentView.Frame      = cell.ContentView.Frame.SetWidth(cellWidth);
                cell.SelectedBackgroundView = new UIView(cell.Frame)
                {
                    BackgroundColor = UIColor.FromRGB(190, 190, 190)
                };
            }

            return(cell);
        }
Example #29
0
        public static CAShapeLayer RoundedMask(RectangleF frame, UIRectCorner corners, float radius)
        {
            UIBezierPath path = UIBezierPath.FromRoundedRect(frame, corners, new SizeF(radius, radius));
            CAShapeLayer layer = new CAShapeLayer();
            layer.Frame = frame;
            layer.Path = path.CGPath;

            return layer;
        }
Example #30
0
 public static void ApplyCornerRadius(this UIView currentView, UIRectCorner radiusCorners, int radius = 5)
 => ApplyCornerRadius(currentView, radiusCorners, false);
Example #31
0
 public UIBezierPath(CGRect roundedRect, UIRectCorner byRoundingCorners, CGSize cornerRadii)
 {
 }
Example #32
0
        private void UpdateButtonBorder(
            UIButton button,
            UIRectCorner corners,
            bool isInFirstRow,
            bool isInLastRow,
            bool isInFirstColumn,
            bool isInLastColumn)
        {
            // we need to handle the situation where borders are next to each other, the problem is
            // this creates an appearance where the border is twice as thick so we will use masking
            // to remove borders from some buttons

            CGSize radius       = new CGSize(Constants.ButtonBorderRadius, Constants.ButtonBorderRadius);
            CGRect borderBounds = button.Bounds;

            if (!isInLastColumn)
            {
                // extend the border to the right so it overlaps with the border of the next button
                borderBounds =
                    new CGRect(
                        button.Bounds.X,
                        button.Bounds.Y,
                        button.Bounds.Width + Constants.ButtonBorderHalfSize,
                        button.Bounds.Height);
            }

            if (!isInLastRow)
            {
                // extend the border down so it overlaps with the border for the next row
                borderBounds = borderBounds.WithHeight(borderBounds.Height + Constants.ButtonBorderHalfSize);
            }

            UIBezierPath path = UIBezierPath.FromRoundedRect(borderBounds, corners, radius);

            CAShapeLayer maskLayer = new CAShapeLayer();

            maskLayer.Frame = borderBounds;
            maskLayer.Path  = path.CGPath;

            button.Layer.Mask = maskLayer;

            CAShapeLayer borderLayer = new CAShapeLayer();

            borderLayer.FillColor   = null;
            borderLayer.Frame       = borderBounds;
            borderLayer.Name        = Constants.ButtonBorderName;
            borderLayer.Path        = path.CGPath;
            borderLayer.StrokeColor = this.buttonBorderColor;
            borderLayer.LineWidth   = Constants.ButtonBorderSize;

            if (button.Layer.Sublayers != null)
            {
                CAShapeLayer oldLayer = button.Layer.Sublayers.SingleOrDefault(layer => layer.Name == Constants.ButtonBorderName) as CAShapeLayer;
                if (oldLayer != null)
                {
                    oldLayer.RemoveFromSuperLayer();
                }
            }

            button.Layer.AddSublayer(borderLayer);
        }
Example #33
0
        void SetCornerRadius()
        {
            var test = Element.CornerRadius;

            if (!string.IsNullOrEmpty(Element.CornerRadius))
            {
                var       cornerRad    = Element.CornerRadius.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                Thickness cornerRadius = new Thickness();

                if (cornerRad.Length == 4)
                {
                    cornerRadius.Left   = float.Parse(cornerRad[0]);
                    cornerRadius.Top    = float.Parse(cornerRad[1]);
                    cornerRadius.Right  = float.Parse(cornerRad[2]);
                    cornerRadius.Bottom = float.Parse(cornerRad[3]);
                }
                else if (cornerRad.Length == 2)
                {
                    cornerRadius.Left   = float.Parse(cornerRad[0]);
                    cornerRadius.Right  = float.Parse(cornerRad[0]);
                    cornerRadius.Top    = float.Parse(cornerRad[1]);
                    cornerRadius.Bottom = float.Parse(cornerRad[1]);
                }
                else
                {
                    int rad;
                    if (int.TryParse(Element.CornerRadius, out rad))
                    {
                        if (rad <= -1)
                        {
                            cornerRadius.Left   = 10;
                            cornerRadius.Right  = 10;
                            cornerRadius.Top    = 10;
                            cornerRadius.Bottom = 10;
                        }
                        else
                        {
                            cornerRadius.Left   = rad;
                            cornerRadius.Right  = rad;
                            cornerRadius.Top    = rad;
                            cornerRadius.Bottom = rad;
                        }
                    }
                }

                int          radius     = 0;
                UIRectCorner forCorners = 0;

                if (cornerRadius.Bottom > 0 &&
                    cornerRadius.Left > 0 &&
                    cornerRadius.Right > 0 &&
                    cornerRadius.Top > 0)
                {
                    forCorners = UIRectCorner.AllCorners;
                    radius     = Convert.ToInt32(cornerRadius.Top);
                }
                else
                {
                    if (cornerRadius.Bottom > 0)
                    {
                        forCorners = forCorners | UIRectCorner.BottomRight;
                        radius     = Convert.ToInt32(cornerRadius.Bottom);
                    }
                    if (cornerRadius.Left > 0)
                    {
                        forCorners = forCorners | UIRectCorner.BottomLeft;
                        radius     = Convert.ToInt32(cornerRadius.Left);
                    }
                    if (cornerRadius.Right > 0)
                    {
                        forCorners = forCorners | UIRectCorner.TopRight;
                        radius     = Convert.ToInt32(cornerRadius.Right);
                    }
                    if (cornerRadius.Top > 0)
                    {
                        forCorners = forCorners | UIRectCorner.TopLeft;
                        radius     = Convert.ToInt32(cornerRadius.Top);
                    }
                }

                Control.SetCornerRadius(radius, forCorners);
            }
            else
            {
                Control.SetCornerRadius(0, UIRectCorner.AllCorners);
            }
        }