public void Print (object sender, EventArgs args)
		{
			UIPrintInteractionController controller = UIPrintInteractionController.SharedPrintController;
			if (controller == null) {
				Console.WriteLine ("Couldn't get shared UIPrintInteractionController");
				return;
			}

			controller.CutLengthForPaper = delegate (UIPrintInteractionController printController, UIPrintPaper paper) {
				// Create a font with arbitrary size so that you can calculate the approximate
  				// font points per screen point for the height of the text.
				UIFont font = textformatter.Font;

				NSString str = new NSString (textField.Text);
				UIStringAttributes attributes = new UIStringAttributes ();
				attributes.Font = font;
				CGSize size = str.GetSizeUsingAttributes (attributes);

				nfloat approximateFontPointPerScreenPoint = font.PointSize / size.Height;

				// Create a new font using a size  that will fill the width of the paper
				font = SelectFont ((float)(paper.PrintableRect.Size.Width * approximateFontPointPerScreenPoint));

				// Calculate the height and width of the text with the final font size
				attributes.Font = font;
				CGSize finalTextSize = str.GetSizeUsingAttributes (attributes);

				// Set the UISimpleTextFormatter font to the font with the size calculated
				textformatter.Font = font;

				// Calculate the margins of the roll. Roll printers may have unprintable areas
			    // before and after the cut.  We must add this to our cut length to ensure the
			    // printable area has enough room for our text.
				nfloat lengthOfMargins = paper.PaperSize.Height - paper.PrintableRect.Size.Height;

				// The cut length is the width of the text, plus margins, plus some padding
				return finalTextSize.Width + lengthOfMargins + paper.PrintableRect.Size.Width * PaddingFactor;
			};

			UIPrintInfo printInfo = UIPrintInfo.PrintInfo;
			printInfo.OutputType = UIPrintInfoOutputType.General;
			printInfo.Orientation = UIPrintInfoOrientation.Landscape;
			printInfo.JobName = textField.Text;

			textformatter = new UISimpleTextPrintFormatter (textField.Text) {
				Color = SelectedColor,
				Font = SelectFont ()
			};

			controller.PrintInfo = printInfo;
			controller.PrintFormatter = textformatter;

			if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
				controller.PresentFromRectInView (printButton.Frame, View, true, PrintingComplete);
			else
				controller.Present (true, PrintingComplete);
		}
        partial void Print(UIButton sender)
        {
            var controller = UIPrintInteractionController.SharedPrintController;

            controller.CutLengthForPaper = delegate(UIPrintInteractionController printController, UIPrintPaper paper)
            {
                // Create a font with arbitrary size so that you can calculate the approximate
                // font points per screen point for the height of the text.
                var font = textFormatter.Font;

                var text       = new NSString(textField.Text);
                var attributes = new UIStringAttributes {
                    Font = font
                };
                var size = text.GetSizeUsingAttributes(attributes);

                nfloat approximateFontPointPerScreenPoint = font.PointSize / size.Height;

                // Create a new font using a size  that will fill the width of the paper
                font = GetSelectedFont((float)(paper.PrintableRect.Size.Width * approximateFontPointPerScreenPoint));

                // Calculate the height and width of the text with the final font size
                attributes.Font = font;
                var finalTextSize = text.GetSizeUsingAttributes(attributes);

                // Set the UISimpleTextFormatter font to the font with the size calculated
                textFormatter.Font = font;

                // Calculate the margins of the roll. Roll printers may have unprintable areas
                // before and after the cut.  We must add this to our cut length to ensure the
                // printable area has enough room for our text.
                nfloat lengthOfMargins = paper.PaperSize.Height - paper.PrintableRect.Size.Height;

                // The cut length is the width of the text, plus margins, plus some padding
                return(finalTextSize.Width + lengthOfMargins + paper.PrintableRect.Size.Width * PaddingFactor);
            };

            var printInfo = UIPrintInfo.PrintInfo;

            printInfo.OutputType  = UIPrintInfoOutputType.General;
            printInfo.Orientation = UIPrintInfoOrientation.Landscape;
            printInfo.JobName     = textField.Text;

            textFormatter = new UISimpleTextPrintFormatter(textField.Text)
            {
                Color = GetSelectedColor(),
                Font  = GetSelectedFont()
            };

            controller.PrintInfo      = printInfo;
            controller.PrintFormatter = textFormatter;
            controller.Present(true, OnPrintingComplete);

            printInfo.Dispose();
            printInfo = null;
        }
        public void GenView(MKClusterAnnotation cluster)
        {
            AnnotationViewSize annotationSize = MapSettings.AnnotationSize;

            if (cluster != null)
            {
                var renderer = new UIGraphicsImageRenderer(new CGSize(annotationSize.Width,
                                                                      annotationSize.Height));
                var count = cluster.MemberAnnotations.Length;

                Image = renderer.CreateImage((context) => {
                    //circle
                    UIColor.FromRGB(230, 141, 119).SetFill();
                    UIBezierPath.FromOval(new CGRect(0,
                                                     0,
                                                     annotationSize.Width,
                                                     annotationSize.Height)).Fill();

                    //text
                    var attributes = new UIStringAttributes()
                    {
                        ForegroundColor = UIColor.Black,
                        Font            = UIFont.BoldSystemFontOfSize(20)
                    };
                    var text = new NSString($"{count}");
                    var size = text.GetSizeUsingAttributes(attributes);
                    var rect = new CGRect(20 - size.Width / 2, 20 - size.Height / 2, size.Width, size.Height);
                    text.DrawString(rect, attributes);
                });
            }
        }
Exemple #4
0
        public override UIView GetView(object shapeData)
        {
            NSDictionary dic = (NSDictionary)shapeData;

            UIView view = new UIView();
            NSString topText = (NSString)(dic["Country"]);
            NSString bottomText = (NSString)(dic["Percent"].ToString() + "%");

            UILabel topLabel = new UILabel();
            topLabel.Text = topText;
            topLabel.Font = UIFont.SystemFontOfSize(12);
            topLabel.TextColor = UIColor.White;
            topLabel.TextAlignment = UITextAlignment.Center;

            UILabel bottomLabel = new UILabel();
            bottomLabel.Text = bottomText;
            bottomLabel.Font = UIFont.SystemFontOfSize(12);
            bottomLabel.TextColor = UIColor.White;
            bottomLabel.TextAlignment = UITextAlignment.Center;

            view.AddSubview(topLabel);
            view.AddSubview(bottomLabel);

            CGSize expectedLabelSize1 = topText.GetSizeUsingAttributes(new UIStringAttributes() { Font = topLabel.Font });
            CGSize expectedLabelSize2 = bottomText.GetSizeUsingAttributes(new UIStringAttributes() { Font = bottomLabel.Font });

            view.Frame = new CGRect(0.0f, 0.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width), 35.0f);
            topLabel.Frame = new CGRect(0.0f, 0.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width), 15.0f);
            bottomLabel.Frame = new CGRect(0.0f, 20.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width), 15.0f);

            return view;
        }
        private UIImage CreateImage (NSString title, nfloat scale)
        {
            var titleAttrs = new UIStringAttributes () {
                Font = UIFont.FromName ("HelveticaNeue", 13f),
                ForegroundColor = Color.Gray,
            };

            var titleBounds = new CGRect (
                new CGPoint (0, 0),
                title.GetSizeUsingAttributes (titleAttrs)
            );

            var image = Image.TagBackground;
            var imageBounds = new CGRect (
                0, 0,
                (float)Math.Ceiling (titleBounds.Width) + image.CapInsets.Left + image.CapInsets.Right + 4f,
                (float)Math.Ceiling (titleBounds.Height) + image.CapInsets.Top + image.CapInsets.Bottom
            );

            titleBounds.X = image.CapInsets.Left + 2f;
            titleBounds.Y = image.CapInsets.Top;

            UIGraphics.BeginImageContextWithOptions (imageBounds.Size, false, scale);

            try {
                image.Draw (imageBounds);
                title.DrawString (titleBounds, titleAttrs);
                return UIGraphics.GetImageFromCurrentImageContext ();
            } finally {
                UIGraphics.EndImageContext ();
            }
        }
        internal void UpdateDetailLabelWithString(string newString, bool animated, Action completion)
        {
            var length            = animated ? AnimationLength : 0.0f;
            var labelWidth        = 15;      //padding
            var attribs           = new UIStringAttributes();
            var nsVersionOfString = new NSString(newString);

            if (!IsLessThanIOS6)
            {
                attribs.Font = DetailLabelFont;
                labelWidth  += (int)nsVersionOfString.GetSizeUsingAttributes(attribs).Width;
            }
            else
            {
                labelWidth += (int)nsVersionOfString.StringSize(DetailLabelFont).Width;
            }

            CATransition animation = new CATransition();

            animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            animation.Type           = CATransition.TransitionFade;
            animation.Duration       = length;
            DetailLabel.Layer.AddAnimation(animation, "kCATransitionFade");
            DetailLabel.Text = newString;
            var pinSelectionTop = EnterPasscodeLabel.Frame.Y + EnterPasscodeLabel.Frame.Size.Height + 17.5;

            DetailLabel.Frame = new RectangleF((CorrectWidth / 2) - 100,
                                               (float)pinSelectionTop + 30f, 200, 23);
        }
Exemple #7
0
        private void updateLabelForLayer(SliceLayer sliceLayer, nfloat value)
        {
            var textLayer = (CATextLayer)sliceLayer.Sublayers [1];

            textLayer.Hidden = !ShowLabel;
            if (!ShowLabel)
            {
                return;
            }

            String label    = ShowPercentage ? sliceLayer.Percentage.ToString("P1") : sliceLayer.Value.ToString("0.00");
            var    nsString = new NSString(label);
            CGSize size     = nsString.GetSizeUsingAttributes(new UIStringAttributes()
            {
                Font = LabelFont
            });

            if (Math.PI * 2 * LabelRadius * sliceLayer.Percentage < Math.Max(size.Width, size.Height) || value <= 0)
            {
                textLayer.String = "";
            }
            else
            {
                textLayer.String = label;
                textLayer.Bounds = new CGRect(0, 0, size.Width, size.Height);
            }
        }
        private UIImage CreateImage(NSString title, float scale)
        {
            var titleAttrs = new UIStringAttributes()
            {
                Font            = UIFont.FromName("HelveticaNeue", 13f),
                ForegroundColor = Color.Gray,
            };

            var titleBounds = new RectangleF(
                new PointF(0, 0),
                title.GetSizeUsingAttributes(titleAttrs)
                );

            var image       = Image.TagBackground;
            var imageBounds = new RectangleF(
                0, 0,
                (float)Math.Ceiling(titleBounds.Width) + image.CapInsets.Left + image.CapInsets.Right + 4f,
                (float)Math.Ceiling(titleBounds.Height) + image.CapInsets.Top + image.CapInsets.Bottom
                );

            titleBounds.X = image.CapInsets.Left + 2f;
            titleBounds.Y = image.CapInsets.Top;

            UIGraphics.BeginImageContextWithOptions(imageBounds.Size, false, scale);

            try {
                image.Draw(imageBounds);
                title.DrawString(titleBounds, titleAttrs);
                return(UIGraphics.GetImageFromCurrentImageContext());
            } finally {
                UIGraphics.EndImageContext();
            }
        }
Exemple #9
0
        void ComputeEdgeInsets(UIButton button, Button.ButtonContentLayout layout)
        {
            if (button?.ImageView?.Image == null || string.IsNullOrEmpty(button.TitleLabel?.Text))
            {
                return;
            }

            var position = layout.Position;
            var spacing  = (nfloat)(layout.Spacing / 2);

            if (position == Button.ButtonContentLayout.ImagePosition.Left)
            {
                button.ImageEdgeInsets = new UIEdgeInsets(0, -spacing, 0, spacing);
                button.TitleEdgeInsets = new UIEdgeInsets(0, spacing, 0, -spacing);
                UpdateContentEdge(button, new UIEdgeInsets(0, 2 * spacing, 0, 2 * spacing));
                return;
            }

            if (_titleChanged)
            {
                var stringToMeasure        = new NSString(button.TitleLabel.Text);
                UIStringAttributes attribs = new UIStringAttributes {
                    Font = button.TitleLabel.Font
                };
                var s = stringToMeasure.GetSizeUsingAttributes(attribs);;
                _titleSize    = new SizeF((float)s.Width, (float)s.Height);
                _titleChanged = false;
            }

            var labelWidth = _titleSize.Width;
            var imageWidth = button.ImageView.Image.Size.Width;

            if (position == Button.ButtonContentLayout.ImagePosition.Right)
            {
                button.ImageEdgeInsets = new UIEdgeInsets(0, labelWidth + spacing, 0, -labelWidth - spacing);
                button.TitleEdgeInsets = new UIEdgeInsets(0, -imageWidth - spacing, 0, imageWidth + spacing);
                UpdateContentEdge(button, new UIEdgeInsets(0, 2 * spacing, 0, 2 * spacing));
                return;
            }

            var imageVertOffset = (_titleSize.Height / 2);
            var titleVertOffset = (button.ImageView.Image.Size.Height / 2);

            var edgeOffset = (float)Math.Min(imageVertOffset, titleVertOffset);

            UpdateContentEdge(button, new UIEdgeInsets(edgeOffset, 0, edgeOffset, 0));

            var horizontalImageOffset = labelWidth / 2;
            var horizontalTitleOffset = imageWidth / 2;

            if (position == Button.ButtonContentLayout.ImagePosition.Bottom)
            {
                imageVertOffset = -imageVertOffset;
                titleVertOffset = -titleVertOffset;
            }

            button.ImageEdgeInsets = new UIEdgeInsets(-imageVertOffset, horizontalImageOffset, imageVertOffset, -horizontalImageOffset);
            button.TitleEdgeInsets = new UIEdgeInsets(titleVertOffset, -horizontalTitleOffset, -titleVertOffset, horizontalTitleOffset);
        }
Exemple #10
0
        public static UIImage GenerateImage(nfloat width, nfloat height, string name = "ME")
        {
            Random rnd = new Random();

            CGColor color = colors[rnd.Next(colors.Length - 1)];

            UIFont font = UIFont.FromName("Helvetica Light", 14);

            UIGraphics.BeginImageContextWithOptions(new CGSize(width, height), false, 0);

            var context = UIGraphics.GetCurrentContext();

            context.SetFillColor(color);
            context.AddArc(width / 2, height / 2, width / 2, 0, (nfloat)(2 * Math.PI), true);
            context.FillPath();

            var textAttributes = new UIStringAttributes
            {
                ForegroundColor = UIColor.White,
                BackgroundColor = UIColor.Clear,
                Font            = font,
                ParagraphStyle  = new NSMutableParagraphStyle {
                    Alignment = UITextAlignment.Center
                },
            };

            string text;

            string[] splitFrom = name.Split(' ');
            if (splitFrom[0] == "ME")
            {
                text = "ME";
            }
            else if (splitFrom.Length > 1)
            {
                text = splitFrom[0][0].ToString() + splitFrom[1][0];
            }
            else if (splitFrom.Length > 0)
            {
                text = splitFrom[0][0].ToString();
            }
            else
            {
                text = "?";
            }

            NSString str = new NSString(text);

            var textSize = str.GetSizeUsingAttributes(textAttributes);

            str.DrawString(new CGRect(0, height / 2 - textSize.Height / 2,
                                      width, height), textAttributes);

            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image);
        }
Exemple #11
0
        public void ReloadData()
        {
            if (DataSource == null)
            {
                return;
            }

            CALayer parentLayer = _barChartView.Layer;
            int     barsCount   = DataSource.NumberOfBarsOnChart(this);

            for (int i = 0; i < xAxisText.Length; i++)
            {
                xAxisText [i].String = DataSource.TimeIntervalAtIndex(i);
            }

            _barChartView.UserInteractionEnabled = false;
            float       barHeight = (Bounds.Height - topBarMargin - yAxisMargin) / Convert.ToSingle(barsCount);
            const float padding   = 1.0f;
            float       initialY  = barHeight / 2 + topBarMargin;

            for (int i = 0; i < barsCount; i++)
            {
                BarLayer oneLayer = CreateBarLayer(barHeight - padding);
                parentLayer.AddSublayer(oneLayer);
                oneLayer.Position   = new PointF(0, initialY + i * barHeight);
                oneLayer.TimeValue  = DataSource.ValueForBarAtIndex(this, i);
                oneLayer.MoneyValue = DataSource.ValueForSecondaryBarAtIndex(this, i);

                var timeTextLayer = (CATextLayer)oneLayer.Sublayers [BarLayer.TimeTextIndex];
                timeTextLayer.String   = DataSource.TimeForBarAtIndex(i);
                timeTextLayer.Hidden   = (string.Compare(timeTextLayer.String, "0.00", StringComparison.Ordinal) == 0);
                timeTextLayer.Position = new PointF(timeTextLayer.Position.X, oneLayer.Bounds.Height / 2);
                timeTextLayer.FontSize = (barsCount > 12) ? 9.0f : 10.0f;

                var   nsString = new NSString(DataSource.TextForBarAtIndex(this, i));
                SizeF size     = nsString.GetSizeUsingAttributes(new UIStringAttributes()
                {
                    Font = LabelFont
                });
                var textLayer = (CATextLayer)oneLayer.Sublayers [BarLayer.DateTextIndex];
                textLayer.String   = DataSource.TextForBarAtIndex(this, i);
                textLayer.FontSize = (barsCount > 12) ? 9.0f : 10.0f;
                textLayer.Bounds   = new RectangleF(0, 0, size.Width, size.Height);
                textLayer.Position = new PointF(0.0f, oneLayer.Bounds.Height / 2);

                if (barsCount > 12)
                {
                    timeTextLayer.Opacity = 0.0f;
                    textLayer.Opacity     = (i % 3 == 0) ? 1.0f : 0.0f;
                }
                else
                {
                    timeTextLayer.Opacity = (string.Compare(timeTextLayer.String, "0.00", StringComparison.Ordinal) == 0) ? 0.0f : 1.0f;
                }
            }
            _barChartView.UserInteractionEnabled = true;
        }
Exemple #12
0
        public void Configure()
        {
            TopPadding = (nfloat)Math.Min(10, this.Frame.Height * 0.1);

            var                font     = UIFont.FromName("System", 10);
            NSString           nsString = new NSString(Results.Max(r => r.Score).ToString());
            UIStringAttributes attribs  = new UIStringAttributes {
                Font = font
            };
            var textSize = nsString.GetSizeUsingAttributes(attribs);

            ScoreSize = textSize;
            nfloat squareSide = (nfloat)(Math.Max(ScoreSize.Width, ScoreSize.Height) / Math.Cos(Math.PI / 4));

            ScoreBubleSize = new CGSize(squareSide, squareSide);

            Offset    = (nfloat)Math.Max(minimalSpacing, this.Frame.Width / Results.Count / 2);
            StartXPos = (this.Frame.Width / 2) + (Offset * (Results.Count - 1));

            CGSize graphSize = new CGSize(this.Frame.Width + (Offset * (Results.Count - 1)), this.Frame.Height);

            this.ContentSize = graphSize;


            nfloat nextPos = StartXPos;

            foreach (var result in Results.OrderByDescending(c => c.ExecutionDate))
            {
                nfloat graphPoint = this.Frame.Height - EndYPos(result.Score);

                var pointStartPath = new CGPath();
                pointStartPath.MoveToPoint(nextPos, this.Frame.Height);
                pointStartPath.AddLineToPoint(nextPos, this.Frame.Height);

                pointStartPathList.Add(pointStartPath);

                var pointEndPath = new CGPath();
                pointEndPath.MoveToPoint(nextPos, this.Frame.Height);
                pointEndPath.AddLineToPoint(nextPos, graphPoint + ScoreBubleSize.Height);

                pointEndPathList.Add(pointEndPath);

                var pointLayer = new CAShapeLayer();

                pointLayer.Path        = pointStartPath;
                pointLayer.StrokeColor = graphColor;
                pointLayer.FillColor   = graphColor;

                pointLayerList.Add(pointLayer);

                this.Layer.AddSublayer(pointLayer);

                nextPos -= Offset;
            }

            this.ContentOffset = new CGPoint((Offset * (Results.Count - 1)), 0);
        }
Exemple #13
0
    private CGSize SizeOfTextForCurrentSettings()
    {
        NSString text = new NSString(BadgeText);

        return(text.GetSizeUsingAttributes(new UIStringAttributes()
        {
            Font = BadgeTextFont
        }));
    }
        public override CGSize GetSizeForItem(UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
        {
            var name = new NSString(Sections[indexPath.Section].Items[indexPath.Row].Name);
            var size = name.GetSizeUsingAttributes(new UIStringAttributes()
            {
                Font = UIFont.SystemFontOfSize(17)
            });

            return(new CGSize(size.Width + 24, 36));
        }
Exemple #15
0
        public static CGSize SizeForStringWithFont(string text, UIFont font)
        {
            NSString           value   = new NSString(text);
            UIStringAttributes attribs = new UIStringAttributes {
                Font = font
            };
            CGSize size = value.GetSizeUsingAttributes(attribs);

            return(size);
        }
        public void displayToastWithMessage(NSString toastMessage, NSString typeLabel)
        {
            UIWindow keyWindow = UIApplication.SharedApplication.KeyWindow;

            if (toastView != null)
            {
                toastView.RemoveFromSuperview();
            }


            toastView = new UIView();
            UILabel label1 = new UILabel();
            UILabel label2 = new UILabel();

            label1.TextColor     = label2.TextColor = UIColor.White;
            label1.Font          = UIFont.SystemFontOfSize(16);
            label1.Text          = toastMessage;
            label2.Text          = typeLabel;
            label2.Font          = UIFont.SystemFontOfSize(12);
            label1.TextAlignment = label2.TextAlignment = UITextAlignment.Center;;
            toastView.AddSubview(label1);
            toastView.AddSubview(label2);

            toastView.Alpha = 1;

            toastView.BackgroundColor    = UIColor.Black.ColorWithAlpha(0.7f);
            toastView.Layer.CornerRadius = 10;

            CGSize expectedLabelSize1 = toastMessage.GetSizeUsingAttributes(new UIStringAttributes()
            {
                Font = label1.Font
            });
            CGSize expectedLabelSize2 = typeLabel.GetSizeUsingAttributes(new UIStringAttributes()
            {
                Font = label2.Font
            });

            keyWindow.AddSubview(toastView);
            toastView.Frame = new CGRect(0.0f, 0.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width) + 20, 45.0f);
            label1.Frame    = new CGRect(0.0f, 5.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width) + 15, 15.0f);
            label2.Frame    = new CGRect(0.0f, 25.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width) + 15, 15.0f);


            toastView.Center = markerView.Center;


            UIView.Animate(4, 0, UIViewAnimationOptions.CurveEaseInOut,
                           () => {
                toastView.Alpha = 0.7f;
            },
                           () => {
                toastView.RemoveFromSuperview();
            }
                           );
        }
Exemple #17
0
		public float ButtonTextSize(string text, double fontSize)
		{
			if (button == null) {
				button = new UIButton();
				button.Font = UIFont.SystemFontOfSize((nfloat)fontSize);
			}

			NSString nsText = new NSString(text);

			return (float)nsText.GetSizeUsingAttributes(new UIStringAttributes() { Font = UIFont.SystemFontOfSize(textSize) }).Width + (float)button.ContentEdgeInsets.Left + (float)button.ContentEdgeInsets.Right;
		}
Exemple #18
0
        public CGSize CalculateSize()
        {
            // Get size of target string using the label's font.
            var nsString = new NSString(this._label.Text);
            UIStringAttributes attribs = new UIStringAttributes {
                Font = this._label.Font
            };
            var size = nsString.GetSizeUsingAttributes(attribs);

            return(size);
        }
        public CGSize GetSizeForItem(UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
        {
            var quickSelectShortcut = (CalendarBaseQuickSelectShortcut)GetItemAt(indexPath);
            var title     = new NSString(quickSelectShortcut.Title);
            var titleSize = title.GetSizeUsingAttributes(titleAttributes);

            return(new CGSize(
                       Math.Ceiling(titleSize.Width) + horizontalPadding,
                       cellHeight
                       ));
        }
            private UIImage GetIconForText(string text, nuint bucketIndex)
            {
                var nsText = new NSString(text);
                var icon   = _iconCache.ObjectForKey(nsText);

                if (icon != null)
                {
                    return((UIImage)icon);
                }

                var font           = UIFont.BoldSystemFontOfSize(14);
                var paragraphStyle = NSParagraphStyle.Default;
                var dict           = NSDictionary.FromObjectsAndKeys(
                    objects: new NSObject[] { font, paragraphStyle, this._options.RendererTextColor.ToUIColor() },
                    keys: new NSObject[] { UIStringAttributeKey.Font, UIStringAttributeKey.ParagraphStyle, UIStringAttributeKey.ForegroundColor }
                    );
                var attributes = new UIStringAttributes(dict);


                var textSize      = nsText.GetSizeUsingAttributes(attributes);
                var rectDimension = Math.Max(20, Math.Max(textSize.Width, textSize.Height)) + 3 * bucketIndex + 6;
                var rect          = new CGRect(0.0f, 0.0f, rectDimension, rectDimension);

                UIGraphics.BeginImageContext(rect.Size);
                UIGraphics.BeginImageContextWithOptions(rect.Size, false, 0);

                // Background circle
                var ctx = UIGraphics.GetCurrentContext();

                ctx.SaveState();

                bucketIndex = (nuint)Math.Min((int)bucketIndex, this._options.BucketColors.Length - 1);
                var backColor = this._options.BucketColors[bucketIndex];

                ctx.SetFillColor(backColor.ToCGColor());
                ctx.FillEllipseInRect(rect);
                ctx.RestoreState();

                // Draw the text
                UIColor.White.SetColor();
                var textRect = RectangleFExtensions.Inset(rect, (rect.Size.Width - textSize.Width) / 2,
                                                          (rect.Size.Height - textSize.Height) / 2);

                nsText.DrawString(RectangleFExtensions.Integral(textRect), attributes);

                var newImage = UIGraphics.GetImageFromCurrentImageContext();

                UIGraphics.EndImageContext();

                this._iconCache.SetObjectforKey(newImage, nsText);

                return(newImage);
            }
        public FloatingButton(string title, string subTitle = null)
        {
            var nsTitle = new NSString(title);
            var size    = nsTitle.GetSizeUsingAttributes(new UIStringAttributes {
                Font = TitleLabel.Font
            });
            var buttonWidth = size.Width + 25;


            Initialize(title, buttonWidth, subTitle);
            this.TranslatesAutoresizingMaskIntoConstraints = false;
            this.WidthAnchor.ConstraintEqualTo(this.Frame.Width).Active = true;
        }
Exemple #22
0
		public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
		{
			var baseResult = base.GetDesiredSize(widthConstraint, heightConstraint);

			if (Forms.IsiOS11OrNewer)
				return baseResult;

			NSString testString = new NSString("Tj");
			var testSize = testString.GetSizeUsingAttributes(new UIStringAttributes { Font = Control.Font });
			double height = baseHeight + testSize.Height - initialSize.Height;
			height = Math.Round(height);

			return new SizeRequest(new Size(baseResult.Request.Width, height));
		}
        private CGSize measureLabel(UILabel label)
        {
            CGSize labelSize = new CGSize();

            if (label.Text.Length > 0)
            {
                NSString           labelString = (NSString)label.Text;
                UIStringAttributes attribs     = new UIStringAttributes {
                    Font = label.Font
                };
                labelSize = labelString.GetSizeUsingAttributes(attribs);
            }
            return(labelSize);
        }
 public void CreateButton(string title, NSObject target, Selector selector, CGPoint origin)
 {
     NSString titleString = new NSString (title);
     UIStringAttributes attributes = new UIStringAttributes () { Font = UIFont.SystemFontOfSize (18) };
     CGSize titleSize = titleString.GetSizeUsingAttributes(attributes);
     UIButton button = new UIButton (new CGRect (origin.X, origin.Y, titleSize.Width, 44));
     button.TitleLabel.Font = UIFont.SystemFontOfSize (14);
     button.Layer.BorderWidth = 1.0f;
     button.Layer.BorderColor = UIColor.White.CGColor;
     button.Layer.CornerRadius = 3.0f;
     button.SetTitle (title, UIControlState.Normal);
     button.SetTitleColor (UIColor.White, UIControlState.Normal);
     button.AddTarget (target, selector, UIControlEvent.TouchUpInside);
     this.SideDrawerView.MainView.AddSubview (button);
 }
Exemple #25
0
 public override void DrawText(CGRect rect)
 {
     if (this.Text != null)
     {
         NSString text = new NSString(this.Text);
         CGSize   size = text.GetSizeUsingAttributes(new UIStringAttributes()
         {
             Font = this.Font
         });
         base.DrawText(new CGRect(0, 0, this.Frame.Width, size.Width));
     }
     else
     {
         base.Draw(rect);
     }
 }
Exemple #26
0
        void AddMainView()
        {
            if (childGrid == null)
            {
                childGrid = new UIView();
            }
            mainGrid = new UIView();
            mainGrid.BackgroundColor = UIColor.FromRGB(243, 239, 233);
            mainGrid.AddSubview(childGrid);
            maps = new SFMap();
            ImageryLayer layer = new ImageryLayer();

            maps.Layers.Add(layer);

            mainGrid.AddSubview(maps);
            label1               = new UILabel();
            label1.TextColor     = UIColor.Black;
            label1.LayoutMargins = new UIEdgeInsets(2, 2, 3, 2);
            label1.Font          = UIFont.FromName("Helvetica", 12);
            var text           = new NSString("©");
            var stringAtribute = new NSDictionary(UIStringAttributeKey.Font, label1.Font,
                                                  UIStringAttributeKey.ForegroundColor, UIColor.Black);
            UIStringAttributes strAtr = new UIStringAttributes(stringAtribute);

            label1.Text            = text;
            label1Size             = text.GetSizeUsingAttributes(strAtr);
            label1.BackgroundColor = UIColor.White;
            mainGrid.AddSubview(label1);
            label2               = new UILabel();
            label2.TextColor     = UIColor.FromRGB(0, 212, 255);
            label2.LayoutMargins = new UIEdgeInsets(1, 2, 3, 2);
            label2.Font          = UIFont.FromName("Helvetica", 12);
            var text1           = new NSString("OpenStreetMap contributors.");
            var stringAtribute1 = new NSDictionary(UIStringAttributeKey.Font, label2.Font,
                                                   UIStringAttributeKey.ForegroundColor, UIColor.FromRGB(0, 212, 255));
            UIStringAttributes strAtr1 = new UIStringAttributes(stringAtribute);

            label2.Text                   = text1;
            label2Size                    = text1.GetSizeUsingAttributes(strAtr1);
            label2.BackgroundColor        = UIColor.White;
            label2.UserInteractionEnabled = true;
            UITapGestureRecognizer tapGesture = new UITapGestureRecognizer();

            tapGesture.ShouldReceiveTouch += TapGesture_ShouldReceiveTouch;
            label2.AddGestureRecognizer(tapGesture);
            mainGrid.AddSubview(label2);
        }
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            CGSize   size        = new CGSize();
            NSString labelString = (NSString)this.TextLabel.Text;

            if (labelString != null)
            {
                UIStringAttributes attribs = new UIStringAttributes {
                    Font = this.TextLabel.Font
                };
                size = labelString.GetSizeUsingAttributes(attribs);
                this.DetailTextLabel.Font          = UIFont.FromName("Helvetica", 10f);
                this.DetailTextLabel.Frame         = new CGRect(size.Width + 20, 5, 60, 30);
                this.DetailTextLabel.TextAlignment = UITextAlignment.Left;
            }
        }
 public void CreateButton(string title, NSObject target, Selector selector)
 {
     NSString titleString = new NSString (title);
     UIStringAttributes attributes = new UIStringAttributes () { Font = UIFont.SystemFontOfSize (18) };
     CGSize titleSize = titleString.GetSizeUsingAttributes(attributes);
     UIButton button = new UIButton (new CGRect (15, 15 + buttonY, titleSize.Width, 44));
     button.TitleLabel.Font = UIFont.SystemFontOfSize (14);
     button.Layer.BorderWidth = 1.0f;
     button.Layer.BorderColor = UIColor.White.CGColor;
     button.Layer.CornerRadius = 3.0f;
     button.SetTitle (title, UIControlState.Normal);
     button.SetTitleColor (UIColor.White, UIControlState.Normal);
     button.AddTarget (target, selector, UIControlEvent.TouchUpInside);
     scrollView.AddSubview (button);
     buttonY += 50;
     scrollView.ContentSize = new CGSize (Math.Max (button.Frame.Width, scrollView.ContentSize.Width), buttonY + 15 + this.View.Bounds.Y);
 }
        private void ComputeBounds()
        {
#if __MACOS__
            var attributes = new NSStringAttributes()
            {
                Font = _textFormat.Native,
            };

            var size = _native.StringSize(attributes);
#else
            var attributes = new UIStringAttributes()
            {
                Font = _textFormat.Native,
            };

            var size = _native.GetSizeUsingAttributes(attributes);
#endif
            _LayoutBounds = new UGRect(
                0F,
                0F,
                (float)size.Width,
                (float)size.Height);
            if (HorizontalAlignment != UGHorizontalAlignment.Left)
            {
                if (HorizontalAlignment == UGHorizontalAlignment.Right)
                {
                    _LayoutBounds.X = Math.Max(0F, _requestedSize.Width - _LayoutBounds.Width);
                }
                else if (HorizontalAlignment == UGHorizontalAlignment.Center)
                {
                    _LayoutBounds.X = Math.Max(0F, (_requestedSize.Width - _LayoutBounds.Width) / 2F);
                }
            }
            if (VerticalAlignment != UGVerticalAlignment.Top)
            {
                if (VerticalAlignment == UGVerticalAlignment.Bottom)
                {
                    _LayoutBounds.Y = Math.Max(0F, _requestedSize.Height - _LayoutBounds.Height);
                }
                else if (VerticalAlignment == UGVerticalAlignment.Center)
                {
                    _LayoutBounds.Y = Math.Max(0F, (_requestedSize.Height - _LayoutBounds.Height) / 2F);
                }
            }
        }
        public override UIView GetView(object shapeData)
        {
            NSArray      array = (NSArray)shapeData;
            NSDictionary dic   = new NSDictionary();

            for (nuint i = 0; i < array.Count; i++)
            {
                dic = array.GetItem <NSDictionary>(i);
            }
            UIView   view       = new UIView();
            NSString topText    = (NSString)(dic["Region"]);
            NSString bottomText = (NSString)(dic["Growth"].ToString() + "%");

            UILabel topLabel = new UILabel();

            topLabel.Text          = topText;
            topLabel.Font          = UIFont.SystemFontOfSize(12);
            topLabel.TextColor     = UIColor.White;
            topLabel.TextAlignment = UITextAlignment.Center;

            UILabel bottomLabel = new UILabel();

            bottomLabel.Text          = bottomText;
            bottomLabel.Font          = UIFont.SystemFontOfSize(12);
            bottomLabel.TextColor     = UIColor.White;
            bottomLabel.TextAlignment = UITextAlignment.Center;

            view.AddSubview(topLabel);
            view.AddSubview(bottomLabel);

            CGSize expectedLabelSize1 = topText.GetSizeUsingAttributes(new UIStringAttributes()
            {
                Font = topLabel.Font
            });
            CGSize expectedLabelSize2 = bottomText.GetSizeUsingAttributes(new UIStringAttributes()
            {
                Font = bottomLabel.Font
            });

            view.Frame        = new CGRect(0.0f, 0.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width), 35.0f);
            topLabel.Frame    = new CGRect(0.0f, 0.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width), 15.0f);
            bottomLabel.Frame = new CGRect(0.0f, 20.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width), 15.0f);

            return(view);
        }
        private void ResizePriceInput(string newText)
        {
            var nsString = new NSString(newText);
            var attribs  = new UIStringAttributes {
                Font = ItemPriceTextField.Font
            };
            var size = nsString.GetSizeUsingAttributes(attribs);

            if (!itemPriceTextFieldXPosInitialized)
            {
                itemPriceTextFieldXPosInitialized = true;
                itemPriceTextFieldXPos            = ItemPriceTextField.Frame.X + ItemPriceTextField.Frame.Width;
            }

            ItemPriceTextField.Frame = new CGRect(itemPriceTextFieldXPos - size.Width, ItemPriceTextField.Frame.Y, size.Width, ItemPriceTextField.Frame.Height);
            ItemPriceTextField.TranslatesAutoresizingMaskIntoConstraints = true;
            ItemPriceTextField.SetNeedsDisplay();
        }
Exemple #32
0
        /// <summary>
        /// Draws the centered string.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="color">The color.</param>
        /// <param name="rect">The rect.</param>
        /// <param name="font">The font.</param>
        private static void DrawCenteredString(NSString text, UIColor color, CGRect rect, UIFont font)
        {
            var paragraphStyle = (NSMutableParagraphStyle)NSParagraphStyle.Default.MutableCopy();

            paragraphStyle.LineBreakMode = UILineBreakMode.TailTruncation;
            paragraphStyle.Alignment     = UITextAlignment.Center;
            var attrs = new UIStringAttributes {
                Font = font, ForegroundColor = color, ParagraphStyle = paragraphStyle
            };
            var size       = text.GetSizeUsingAttributes(attrs);
            var targetRect = new CGRect(
                rect.X + (float)Math.Floor((rect.Width - size.Width) / 2f),
                rect.Y + (float)Math.Floor((rect.Height - size.Height) / 2f),
                size.Width,
                size.Height);

            text.DrawString(targetRect, attrs);
        }
        public void CreateButton(string title, NSObject target, Selector selector, CGPoint origin)
        {
            NSString           titleString = new NSString(title);
            UIStringAttributes attributes  = new UIStringAttributes()
            {
                Font = UIFont.SystemFontOfSize(18)
            };
            CGSize   titleSize = titleString.GetSizeUsingAttributes(attributes);
            UIButton button    = new UIButton(new CGRect(origin.X, origin.Y, titleSize.Width, 44));

            button.TitleLabel.Font    = UIFont.SystemFontOfSize(14);
            button.Layer.BorderWidth  = 1.0f;
            button.Layer.BorderColor  = UIColor.White.CGColor;
            button.Layer.CornerRadius = 3.0f;
            button.SetTitle(title, UIControlState.Normal);
            button.SetTitleColor(UIColor.White, UIControlState.Normal);
            button.AddTarget(target, selector, UIControlEvent.TouchUpInside);
            this.SideDrawerView.MainView.AddSubview(button);
        }
Exemple #34
0
        nfloat GetStringWidth(NSString str, UIFont font)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }
            if (font == null)
            {
                throw new ArgumentNullException(nameof(font));
            }

            var fontAttributes = new NSMutableDictionary
            {
                [UIStringAttributeKey.Font] = font
            };

            var attributes = new UIStringAttributes(fontAttributes);

            return(str.GetSizeUsingAttributes(attributes).Width);
        }
Exemple #35
0
        public override SizeF MeasureString(String text, Font font)
        {
            CGSize ret;

            var str = new NSString(text ?? "");
            var f   = font.Bold ? UIFont.BoldSystemFontOfSize(font.Size) : UIFont.SystemFontOfSize(font.Size);

            if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                var attributes = new UIStringAttributes {
                    Font = f
                };
                ret = str.GetSizeUsingAttributes(attributes);
            }
            else
            {
                ret = str.StringSize(f);
            }
            return(new SizeF((float)ret.Width, (float)ret.Height));
        }
        public override void Draw (CGRect rect)
        {
            float x = 105;
            float y = 105;
            float r = 100;
            float twopi = (2f * (float)Math.PI) * -1f;
            
            CGContext ctx = UIGraphics.GetCurrentContext ();
            
            //base circle
            UIColor.FromRGB (137, 136, 133).SetColor ();
            ctx.AddArc (x, y, r + 3, 0, twopi, true);
            ctx.FillPath ();
            
            //border circle
            UIColor.FromRGB (231, 231, 231).SetColor ();
            ctx.AddArc (x, y, r, 0, twopi, true);
            ctx.FillPath ();

            //Center circle
            UIColor.White.SetColor ();
            ctx.AddArc (x, y, r / 1.2f, 0, twopi, true);
            ctx.FillPath ();

            UIColor.Black.SetFill ();
            //fast
            NSString text = new NSString("Fast");
            CGSize stringSize = text.GetSizeUsingAttributes(new UIStringAttributes { Font = font10 });
            text.DrawString (new CGPoint (105 - r + 7, 105 + r / 2 - 28), stringSize.Width, font10, UILineBreakMode.TailTruncation);
            
            //Slow
            text = new NSString("Slow");
            stringSize = text.GetSizeUsingAttributes(new UIStringAttributes { Font = font10 });
            text.DrawString (new CGPoint (105 + r - 25, 105 - r / 2 + 20), stringSize.Width, font10, UILineBreakMode.TailTruncation);

            //pubnub
            UIColor.Red.SetFill ();
            text = new NSString("PubNub");
            stringSize = text.GetSizeUsingAttributes(new UIStringAttributes { Font = font18b });
            text.DrawString (new CGPoint ((r * 2 - stringSize.Width) / 2 + 5, y - r / 2f), stringSize.Width, font18b, UILineBreakMode.TailTruncation);


            //needle
            //double percentFromMaxValue = max / 100.0d;
            max = 1000;
            double percentFromMaxValue = max / 100.0d;

            if (lag > max) {
                lag = max;
            }

            //angle
            double invertLag = ((max - min) / 2 - lag) * 2 + lag;
            //Debug.WriteLine("lag: "+ lag.ToString() + " invlag:" + invLag.ToString());
            double angle = 360 - Math.Round ((double)invertLag / percentFromMaxValue * (90 / 100.0f)) * Math.PI / 180.0;
            //double angle2  = 360 - Math.Round((double)lag / percentFromMaxValue* (90 / 100.0f)) * Math.PI / 180.0;;
            //Debug.WriteLine("lagangle: "+ angle.ToString() + " invLagangle" + angle2.ToString());
            //double angle = WrapValue(lag, max);
            
            float distance = 80;
            CGPoint p = new CGPoint (distance * (float)Math.Cos (angle), distance * (float)Math.Sin (angle));
            
            UIColor.Brown.SetStroke ();
            CGPath path1 = new CGPath ();
            ctx.SetLineWidth (3);
            
            CGPoint newPoint = new CGPoint (105 - p.X, 105 - p.Y);
            
            CGPoint[] linePoints = new CGPoint[] { 
                newPoint,
                new CGPoint (105, 105)
            };
            
            path1.AddLines (linePoints);
            path1.CloseSubpath ();
            
            ctx.AddPath (path1);
            ctx.DrawPath (CGPathDrawingMode.FillStroke);

            //caliberate
            UIColor.Brown.SetColor ();
            double theta = 0.0;
            for (int i = 0; i < 360; i++) {
                float bx4 = (float)(x - 4 + (r - 10) * (Math.Cos (theta * Math.PI / 180)));
                float by4 = (float)(y - 15 + (r - 10) * (Math.Sin (theta * Math.PI / 180)));

                NSString dotText = new NSString(".");
                if ((theta > 160) && (theta < 350)) {
                    UIColor.Black.SetColor ();
                    dotText.DrawString (new CGPoint (bx4, by4), (dotText.GetSizeUsingAttributes(new UIStringAttributes { Font = font18b })).Width, font18b, UILineBreakMode.TailTruncation);
                } else if (((theta >= 0) && (theta < 40)) || ((theta >= 350) && (theta <= 360))) {
                    //redline
                    UIColor.Red.SetColor ();
                    dotText.DrawString (new CGPoint (bx4, by4), (dotText.GetSizeUsingAttributes(new UIStringAttributes { Font = font18b })).Width, font18b, UILineBreakMode.TailTruncation);
                }
                theta += 10.0;

            }

            //small circle
            UIColor.FromRGB (220, 214, 194).SetColor ();
            //ctx.AddArc (x, y+y*.33f, r/1.5f, 0, twopi, true );
            ctx.AddArc (x, y + r / 2f, r / 2f, 0, twopi, true);
            ctx.FillPath ();
            
            //speed in small circle
            UIColor.Black.SetFill ();
            NSString lagText = new NSString (Convert.ToInt32 (lag).ToString ());
            stringSize = lagText.GetSizeUsingAttributes(new UIStringAttributes { Font = font18b });
            lagText.DrawString (new CGPoint ((r * 2 - stringSize.Width) / 2 + 4, y + r / 2f - 15), stringSize.Width, font18b, UILineBreakMode.TailTruncation);

            //ms
            UIColor.Black.SetFill ();
            NSString msText = new NSString ("MS");
            stringSize = msText.GetSizeUsingAttributes(new UIStringAttributes { Font = font18b });
            msText.DrawString (new CGPoint ((r - stringSize.Width) / 2 + 55, y + r / 2f + 10), stringSize.Width, font18b, UILineBreakMode.TailTruncation);
        }
        public UIImage GetImage()
        {
            nfloat width = 32;
            nfloat height = 32;

            CGColor color = colors[DataGenerator.RNG.Next(colors.Length - 1)];

            UIFont font = UIFont.FromName("Helvetica Light", 14);
            UIGraphics.BeginImageContextWithOptions(new CGSize(width,height), false, 0);

            var context = UIGraphics.GetCurrentContext();
            context.SetFillColor(color);
            context.AddArc(width / 2, height / 2, width / 2, 0, (nfloat)(2 * Math.PI), true);
            context.FillPath();

            var textAttributes = new UIStringAttributes {
                ForegroundColor = UIColor.White,
                BackgroundColor = UIColor.Clear,
                Font = font,
                ParagraphStyle = new NSMutableParagraphStyle { Alignment = UITextAlignment.Center },
            };

            string text;
            string[] splitFrom = From.Split(' ');
            if (splitFrom.Length > 1) {
                text = splitFrom[0][0].ToString() + splitFrom[1][0];
            } else if (splitFrom.Length > 0) {
                text = splitFrom[0][0].ToString();
            } else {
                text = "?";
            }

            NSString str = new NSString(text);

            var textSize = str.GetSizeUsingAttributes(textAttributes);
            str.DrawString(new CGRect(0, height/2 - textSize.Height/2, 
                width, height), textAttributes);

            UIImage image = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();

            return image;
        }
		void UpdateImage()
		{
			UIImage newImage;
			string number = ((BadgeImage)Element).Number.ToString();
			CGSize size = new CGSize(image.Size.Width, image.Size.Height);

			// Begin a graphics context of sufficient size
			UIGraphics.BeginImageContextWithOptions(size, false, 0f);

			// Draw original image into the context
			if (((BadgeImage)Element).Selected)
			{
				image.Draw(new CGPoint(0, 0));
			}
			else
			{
				// Found at http://iosdevelopertips.com/graphics/convert-an-image-uiimage-to-grayscale.html

				// Create image rectangle with current image width/height
				CGRect imageRect = new CGRect(new CGPoint(0, 0), new CGSize(image.Size.Width * image.CurrentScale, image.Size.Width * image.CurrentScale));

				// Grayscale color space
				CGColorSpace colorSpace = CGColorSpace.CreateDeviceGray();
				CGImage grayImage;
				CGImage mask;

				// Create bitmap content with current image size and grayscale colorspace
				using (var context = new CGBitmapContext(null, (int)image.Size.Width * (int)image.CurrentScale, (int)image.Size.Height * (int)image.CurrentScale, 8, 0, colorSpace, CGImageAlphaInfo.None))
				{

					// Draw image into current context, with specified rectangle
					// using previously defined context (with grayscale colorspace)
					context.DrawImage(imageRect, image.CGImage);

					/* changes start here */
					// Create bitmap image info from pixel data in current context
					grayImage = context.ToImage();

					// release the colorspace and graphics context
					colorSpace.Dispose();
				}

				// Make a new alpha-only graphics context
				using (var context = new CGBitmapContext(null, (int)image.Size.Width * (int)image.CurrentScale, (int)image.Size.Height * (int)image.CurrentScale, 8, 0, CGColorSpace.Null, CGImageAlphaInfo.Only))
				{

					// Draw image into context with no colorspace
					context.DrawImage(imageRect, image.CGImage);

					// Create alpha bitmap mask from current context
					mask = context.ToImage();
				}

				// Make UIImage from grayscale image with alpha mask
				UIImage grayScaleImage = new UIImage(grayImage.WithMask(mask), image.CurrentScale, image.Orientation); //image.CurrentScale

				// Release the CG images
				grayImage.Dispose();
				mask.Dispose();

				grayScaleImage.Draw(new CGPoint(0, 0));
			}

			// Get the context for CoreGraphics
			using (var context = UIGraphics.GetCurrentContext()) {

				if (((BadgeImage)Element).Number > 0) {
					// Save active state of context
					context.SaveState();

					// Calc text size
					float fontSize = 18f;

					var text = new NSString(number); //, UIFont.BoldSystemFontOfSize(fontSize), Color.White.ToUIColor(), Color.Red.ToUIColor());
					var attr = new UIStringAttributes();

					attr.Font = Font.SystemFontOfSize(fontSize).ToUIFont(); //WithAttributes(FontAttributes.Bold).ToUIFont();
					attr.ForegroundColor = Color.White.ToUIColor();
					attr.BackgroundColor = Color.Transparent.ToUIColor();
					attr.ParagraphStyle = new NSParagraphStyle();

					var textSize = text.GetSizeUsingAttributes(attr);

					var badgeWidth = textSize.Width + 9;
					var badgeHeight = textSize.Height + 0;

					if (badgeWidth < badgeHeight)
						badgeWidth = badgeHeight;

					float left = (float)(size.Width - badgeWidth);
					float top = 0; //(float)(size.Height - badgeHeight);

					using (UIBezierPath path = UIBezierPath.FromRoundedRect(new CGRect(left, top, badgeWidth, badgeHeight), UIRectCorner.AllCorners, new CGSize(10, 10))) 
					{
						var color = ((BadgeImage)Element).Selected ? Color.Red.ToCGColor() : Color.FromRgb(192, 192, 192).ToCGColor();

						context.SetFillColor(color);
						context.SetStrokeColor(color);
						context.SetLineWidth(0.0f);

						context.AddPath(path.CGPath);
						context.DrawPath(CGPathDrawingMode.FillStroke);
					}

					text.DrawString(new CGPoint(left + (badgeWidth - textSize.Width) / 2f, top), attr);

					// Restore saved state of context
					context.RestoreState();
				}

				// make image out of bitmap context
				newImage = UIGraphics.GetImageFromCurrentImageContext();
			}

			// free the context
			UIGraphics.EndImageContext();

			this.Control.Image = newImage;
		}
Exemple #39
0
        public void ReloadData()
        {
            if (DataSource == null) {
                return;
            }

            CALayer parentLayer = _barChartView.Layer;
            var barsCount = DataSource.NumberOfBarsOnChart (this);

            for (int i = 0; i < xAxisText.Length; i++) {
                xAxisText [i].String = DataSource.TimeIntervalAtIndex (i);
            }

            _barChartView.UserInteractionEnabled = false;
            nfloat barHeight = (Bounds.Height - topBarMargin - yAxisMargin) / barsCount;
            nfloat padding = 1.0f;
            nfloat initialY = barHeight / 2 + topBarMargin;

            for (int i = 0; i < barsCount; i++) {
                BarLayer oneLayer = CreateBarLayer (barHeight - padding);
                parentLayer.AddSublayer (oneLayer);
                oneLayer.Position = new CGPoint ( 0, initialY + i * barHeight);
                oneLayer.TimeValue = DataSource.ValueForBarAtIndex (this, i);
                oneLayer.MoneyValue = DataSource.ValueForSecondaryBarAtIndex (this, i);

                var timeTextLayer = (CATextLayer)oneLayer.Sublayers [BarLayer.TimeTextIndex];
                timeTextLayer.String = DataSource.TimeForBarAtIndex (i);
                timeTextLayer.Hidden = (string.Compare (timeTextLayer.String, "0.00", StringComparison.Ordinal) == 0);
                timeTextLayer.Position = new CGPoint ( timeTextLayer.Position.X, oneLayer.Bounds.Height/2);
                timeTextLayer.FontSize = (barsCount > 12) ? 9.0f : 10.0f;

                var nsString = new NSString ( DataSource.TextForBarAtIndex (this, i));
                CGSize size = nsString.GetSizeUsingAttributes (new UIStringAttributes () { Font = LabelFont });
                var textLayer = (CATextLayer)oneLayer.Sublayers [BarLayer.DateTextIndex];
                textLayer.String = DataSource.TextForBarAtIndex (this, i);
                textLayer.FontSize = (barsCount > 12) ? 9.0f : 10.0f;
                textLayer.Bounds = new CGRect (0, 0, size.Width, size.Height);
                textLayer.Position = new CGPoint ( 0.0f, oneLayer.Bounds.Height/2);

                if (barsCount > 12) {
                    timeTextLayer.Opacity = 0.0f;
                    textLayer.Opacity = (i % 3 == 0) ? 1.0f : 0.0f;
                } else {
                    timeTextLayer.Opacity = (string.Compare (timeTextLayer.String, "0.00", StringComparison.Ordinal) == 0) ? 0.0f : 1.0f;
                }
            }
            _barChartView.UserInteractionEnabled = true;
        }
Exemple #40
0
        private void updateLabelForLayer (SliceLayer sliceLayer, nfloat value)
        {
            var textLayer = (CATextLayer)sliceLayer.Sublayers [1];
            textLayer.Hidden = !ShowLabel;
            if (!ShowLabel) {
                return;
            }

            String label = ShowPercentage ? sliceLayer.Percentage.ToString ("P1") : sliceLayer.Value.ToString ("0.00");
            var nsString = new NSString (label);
            CGSize size = nsString.GetSizeUsingAttributes (new UIStringAttributes () { Font = LabelFont });

            if (Math.PI * 2 * LabelRadius * sliceLayer.Percentage < Math.Max (size.Width, size.Height) || value <= 0) {
                textLayer.String = "";
            } else {
                textLayer.String = label;
                textLayer.Bounds = new CGRect (0, 0, size.Width, size.Height);
            }
        }
        private SizeF MeasureTitle(int index)
        {
            var title = sectionTitles[index];
            var size = SizeF.Empty;
            var selected = index == SelectedIndex;

            if (TitleFormatter == null)
            {
                var nsTitle = new NSString(title);
                var stringAttributes = selected ? GetSelectedTitleTextAttributes() : GetTitleTextAttributes();
                size = new Version(UIDevice.CurrentDevice.SystemVersion).Major < 7 ? nsTitle.StringSize(stringAttributes.Font) : nsTitle.GetSizeUsingAttributes(stringAttributes);
            }
            else
            {
                size = TitleFormatter(this, title, index, selected).Size;
            }

            return size;
        }
Exemple #42
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            // Get current drawing context
            CGContext ctx = UIGraphics.GetCurrentContext();
            // Get bounds of view
            CGRect bounds = this.Bounds;

            // Figure out the center of the bounds rectangle
            CGPoint center = new CGPoint();
            center.X = (float)(bounds.Location.X + bounds.Size.Width / 2.0);
            center.Y = (float)(bounds.Location.Y + bounds.Size.Height / 2.0);

            // The radius of the circle shiuld be nearly as big as the View.
            float maxRadius = (float)Math.Sqrt(Math.Pow(bounds.Size.Width,2) + Math.Pow(bounds.Size.Height,2)) / 2.0f;

            // The thickness of the line should be 10 points wide
            ctx.SetLineWidth(10);

            // The color of the line should be grey
            //ctx.SetRGBStrokeColor(0.6f, 0.6f, 0.6f, 1.0f);
            //UIColor.FromRGB(0.6f, 0.6f, 0.6f).SetStroke();
            //UIColor.FromRGBA(0.6f, 0.6f, 0.6f, 1.0f).SetStroke();
            circleColor.SetStroke();

            // Add a shape to the context
            //ctx.AddArc(center.X, center.Y, maxRadius, 0, (float)(Math.PI * 2), true);

            // Perform the drawing operation - draw current shape with current state
            //ctx.DrawPath(CGPathDrawingMode.Stroke);

            float r = 1;
            float g = 0;
            float b = 0;

            // Draw concentric circles from the outside in
            for (float currentRadius = maxRadius; currentRadius > 0; currentRadius -= 20) {
                ctx.AddArc(center.X, center.Y, currentRadius, 0, (float)(Math.PI * 2), true);
                ctx.SetStrokeColor(r ,g, b, 1);
                if (r > 0) {
                    r -= 0.15f;
                    g += 0.15f;
                }
                else if (g > 0) {
                    g -= 0.15f;
                    b += 0.15f;
                }
                ctx.DrawPath(CGPathDrawingMode.Stroke);
            }

            // Create a string
            NSString text = new NSString("You are getting sleepy");

            // Get a font to draw it in
            UIFont font = UIFont.BoldSystemFontOfSize(28);

            CGRect textRect = new CGRect();

            // How big is the string when drawn in this font?
            //textRect.Size = text.StringSize(font);
            UIStringAttributes attribs = new UIStringAttributes {Font = font};
            textRect.Size = text.GetSizeUsingAttributes(attribs);

            // Put the string in the center
            textRect.X = (float)(center.X - textRect.Size.Width / 2.0);
            textRect.Y = (float)(center.Y - textRect.Size.Height / 2.0);

            // Set the fill color of the current context to black
            UIColor.Black.SetFill();

            // Shadow
            CGSize offset = new CGSize(4, 3);
            CGColor color = new CGColor(0.2f, 0.2f, 0.2f, 1f);

            ctx.SetShadow(offset, 2.0f, color);

            // Draw the string
            text.DrawString(textRect, font);

            // Crosshair
            ctx.SaveState();
            CGSize offset2 = new CGSize(0, 0);
            CGColor color2 = new CGColor(UIColor.Clear.CGColor.Handle);
            crossHairColor = UIColor.Green;
            crossHairColor.SetStroke();

            ctx.SetShadow(offset2, 0, color2);
            ctx.SetLineWidth(7);
            ctx.MoveTo(center.X -20, center.Y);
            ctx.AddLineToPoint(center.X + 20, center.Y);
            ctx.DrawPath(CGPathDrawingMode.Stroke);
            ctx.MoveTo(center.X, center.Y-20);
            ctx.AddLineToPoint(center.X, center.Y + 20);
            ctx.DrawPath(CGPathDrawingMode.Stroke);
            ctx.RestoreState();
        }
 /// <summary>
 /// Draws the centered string.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="color">The color.</param>
 /// <param name="rect">The rect.</param>
 /// <param name="font">The font.</param>
 private static void DrawCenteredString(NSString text, UIColor color, CGRect rect, UIFont font)
 {
     var paragraphStyle = (NSMutableParagraphStyle)NSParagraphStyle.Default.MutableCopy();
     paragraphStyle.LineBreakMode = UILineBreakMode.TailTruncation;
     paragraphStyle.Alignment = UITextAlignment.Center;
     var attrs = new UIStringAttributes { Font = font, ForegroundColor = color, ParagraphStyle = paragraphStyle };
     var size = text.GetSizeUsingAttributes(attrs);
     var targetRect = new CGRect(
         rect.X + (float)Math.Floor((rect.Width - size.Width) / 2f),
         rect.Y + (float)Math.Floor((rect.Height - size.Height) / 2f),
         size.Width,
         size.Height);
     text.DrawString(targetRect, attrs);
 }
		/// <summary>
		/// Draws the date string.
		/// </summary>
		/// <param name="dateString">The date string.</param>
		/// <param name="color">The color.</param>
		/// <param name="rect">The rect.</param>
		private void DrawDateString(NSString dateString, UIColor color, CGRect rect)
		{
			if (paragraphStyle == null)
			{
				paragraphStyle = (NSMutableParagraphStyle)NSParagraphStyle.Default.MutableCopy();
				paragraphStyle.LineBreakMode = UILineBreakMode.TailTruncation;
				paragraphStyle.Alignment = UITextAlignment.Center;

			}
			var attrs = new UIStringAttributes()
			{
				Font = _mv.StyleDescriptor.DateLabelFont,
				ForegroundColor = color,
				ParagraphStyle = paragraphStyle
			};
			var size = dateString.GetSizeUsingAttributes(attrs);
			var targetRect = new CGRect(
				rect.X + (float)Math.Floor((rect.Width - size.Width) / 2f),
				rect.Y + (float)Math.Floor((rect.Height - size.Height) / 2f),
										size.Width,
										size.Height
									);
			dateString.DrawString(targetRect, attrs);
		}
		public void displayToastWithMessage(NSString toastMessage,NSString typeLabel)
		{   
			   
			UIWindow keyWindow = UIApplication.SharedApplication.KeyWindow;
			if(toastView!=null)
				{
				toastView.RemoveFromSuperview();
				}


			toastView = new UIView ();
			UILabel label1 = new UILabel ();
			UILabel label2=new UILabel ();
			label1.TextColor = label2.TextColor = UIColor.White;
			label1.Font = UIFont.SystemFontOfSize (16);
			label1.Text= toastMessage;
			label2.Text = typeLabel;
			label2.Font =UIFont.SystemFontOfSize (12);
			label1.TextAlignment = label2.TextAlignment = UITextAlignment.Center;;
			toastView.AddSubview (label1);
			toastView.AddSubview (label2);

			toastView.Alpha =1;

			toastView.BackgroundColor = UIColor.Black.ColorWithAlpha (0.7f);
			toastView.Layer.CornerRadius = 10;

			CGSize expectedLabelSize1= toastMessage.GetSizeUsingAttributes (new UIStringAttributes() { Font = label1.Font });
			CGSize expectedLabelSize2= typeLabel.GetSizeUsingAttributes (new UIStringAttributes() { Font = label2.Font });
			keyWindow.AddSubview(toastView);
			toastView.Frame = new CGRect(0.0f, 0.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width)+20, 45.0f);
			label1.Frame = new CGRect(0.0f, 5.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width)+15, 15.0f);
			label2.Frame = new CGRect(0.0f, 25.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width)+15, 15.0f);


			toastView.Center = markerView.Center;


				UIView.Animate (4, 0, UIViewAnimationOptions.CurveEaseInOut,
					() => {
						toastView.Alpha= 0.7f;
						}, 
				() => {
					
					toastView.RemoveFromSuperview();
						 }
				);


		}