Esempio n. 1
0
        CAShapeLayer CreateShapeLayerWithBezierPath(UIBezierPath bezierPath)
        {
            /* Expand the shape bounds, so when it scales down a bit in the beginning, we have some padding */
            var shapeBounds = Bounds.Inset(-Bounds.Width, -Bounds.Height);

            using (var mutablePath = new CGPath()) {
                mutablePath.AddRect(shapeBounds);

                /* Move the icon to the middle */
                var iconOffset = new CGPoint((Bounds.Width - bezierPath.Bounds.Width) / 2,
                                             (Bounds.Height - bezierPath.Bounds.Height) / 2);

                var iconTransform = CGAffineTransform.MakeTranslation(iconOffset.X, iconOffset.Y);

                mutablePath.AddPath(iconTransform, bezierPath.CGPath);

                var shapeLayer = (CAShapeLayer)CAShapeLayer.Create();
                shapeLayer.Bounds      = shapeBounds;
                shapeLayer.Position    = new CGPoint(Bounds.Width / 2, Bounds.Height / 2);
                shapeLayer.Path        = mutablePath;
                shapeLayer.AnchorPoint = new CGPoint(0.5, 0.5);
                shapeLayer.FillColor   = BackgroundViewColor.CGColor;

                return(shapeLayer);
            }
        }
        private void AddCircles()
        {
            CGAffineTransform tnull = CGAffineTransform.MakeIdentity();

            for (circleNumber = 0; circleNumber < maxCircleNumber; circleNumber++)
            {
                RectangleF   f           = new RectangleF((Frame.Width - circleSize) / 2 - 1, Frame.Height - circleSize - 1, circleSize + 2, circleSize + 2);
                CAShapeLayer circleLayer = (CAShapeLayer)CAShapeLayer.Create();
                circleLayer.Frame = f;
                f.X = 0; f.Y = 0;
                CGPath p = CGPath.EllipseFromRect(f, tnull);                // crash in monotouch! - waiting for fix.
                circleLayer.Path      = p;
                circleLayer.FillColor = Color.CGColor;
                Layer.AddSublayer(circleLayer);
            }
        }
Esempio n. 3
0
        void AddChipLayerAtColumnRowColor(int column, int row, UIColor color)
        {
            int count = chipLayers [column].Count(c => c != null);

            if (count < row + 1)
            {
                var newChip = (CAShapeLayer)CAShapeLayer.Create();
                newChip.Path      = chipPath.CGPath;
                newChip.Frame     = chipPath.Bounds;
                newChip.FillColor = color.CGColor;
                newChip.Position  = PositionForChipLayerAtColumnRow(column, row);

                View.Layer.AddSublayer(newChip);
                CABasicAnimation animation = CABasicAnimation.FromKeyPath("position.y");
                animation.From     = NSNumber.FromNFloat(newChip.Frame.Height);
                animation.To       = NSNumber.FromNFloat(newChip.Position.Y);
                animation.Duration = 0.5;

                animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
                newChip.AddAnimation(animation, null);
                chipLayers [column] [row] = newChip;
            }
        }
Esempio n. 4
0
        private void CommonInit()
        {
            var frame = this.Frame;

            frame.Height = 43.0f;
            this.Frame   = frame;

            // Init properties
            mLastSelectedSegmentIndex = -1;
            mSelectedSegmentIndex     = -1;
            arrowHeightFactor         = -1.0f;
            arrowPosition             = DHSegmentedArrowPosition.Bottom;
            interItemSpace            = Defaults.kSDSegmentedControlInterItemSpace;
            stainEdgeInsets           = Defaults.kSDSegmentedControlStainEdgeInsets;

            mItems = new List <UIView>();

            // Appearance properties
            animationDuration     = Defaults.kSDSegmentedControlDefaultDuration;
            arrowSize             = Defaults.kSDSegmentedControlArrowSize;
            this.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

            // Reset UIKit original widget
            this.Subviews.ToList().ForEach(x => x.RemoveFromSuperview());

            this.Layer.BackgroundColor = UIColor.Clear.CGColor;

            if (!IsiOS7)
            {
                this.BackgroundColor = new UIColor(0.961f, 0.961f, 0.961f, 1.0f);
                this.ShadowColor     = UIColor.Black;
                this.ShadowRadius    = 0.8f;
                this.ShadowOpacity   = 0.6f;
                this.ShadowOffset    = new CGSize(0, 1);
            }
            else
            {
                this.BackgroundColor = UIColor.Clear;
            }

            mBorderBottomLayer = (CAShapeLayer)CAShapeLayer.Create();
            this.Layer.AddSublayer(mBorderBottomLayer);

            if (!IsiOS7)
            {
                this.BorderColor = UIColor.White;
                this.BorderWidth = 0.5f;
            }
            else
            {
                this.BorderColor = UIColor.Black;
                this.BorderWidth = 0.25f;
            }

            mBorderBottomLayer.FillColor = null;

            scrollView = new UIScrollView();
            this.Add(scrollView);

            scrollView.Delegate        = new DSSegmentControlScollViewDelegate();
            scrollView.ScrollsToTop    = false;
            scrollView.BackgroundColor = UIColor.Clear;
            scrollView.ShowsVerticalScrollIndicator   = false;
            scrollView.ShowsHorizontalScrollIndicator = false;

            mSelectedStainView = new DHStainView();

            scrollView.Add(mSelectedStainView);
        }
Esempio n. 5
0
 public BezierView()
 {
     shapeLayer           = (CAShapeLayer)CAShapeLayer.Create();
     shapeLayer.FillColor = new UIColor(0, 0, 0, 0).CGColor;
     Layer.AddSublayer(shapeLayer);
 }
Esempio n. 6
0
        public override void UpdateLayer()
        {
            base.UpdateLayer();

            if (image != null && imageLayer == null)
            {
                Layer.MasksToBounds = false;

                if (maskLayer == null)
                {
                    maskLayer = CAShapeLayer.Create() as CAShapeLayer;
                    Layer.AddSublayer(maskLayer);
                    maskLayer.Path = CGPath.FromRoundedRect(Bounds, cornerRadius, cornerRadius);
                }

                imageLayer               = CALayer.Create();
                imageLayer.Mask          = maskLayer;
                imageLayer.MasksToBounds = true;

                image.LockFocus();
                imageLayer.Contents        = image.CGImage;
                imageLayer.ContentsGravity = CALayer.GravityResizeAspectFill;
                image.UnlockFocus();

                Layer.AddSublayer(imageLayer);
            }

            if (image == null)
            {
                imageLayer?.RemoveFromSuperLayer();
            }

            if (overlayAlpha > 0 && overlayLayer == null)
            {
                overlayLayer = new CALayer();
                overlayLayer.BackgroundColor = overlayColor.ColorWithAlphaComponent(overlayAlpha).CGColor;
                Layer.AddSublayer(overlayLayer);
            }

            if (overlayAlpha == 0 && overlayLayer != null)
            {
                overlayLayer.RemoveFromSuperLayer();
                overlayLayer = null;
            }

            CATransaction.Begin();
            CATransaction.DisableActions = true;

            if (imageLayer != null)
            {
                if (imageLayer.Bounds.Width != Bounds.Width)
                {
                    imageLayer.Frame = Bounds;
                    maskLayer.Path   = CGPath.FromRoundedRect(Bounds, cornerRadius, cornerRadius);
                }
            }

            if (overlayLayer != null && overlayLayer.SuperLayer != null && overlayLayer.Frame != Bounds)
            {
                overlayLayer.Frame = Bounds;
            }

            CATransaction.Commit();
        }