当前位置: 首页>>代码示例>>C#>>正文


C# NSString.GetSizeUsingAttributes方法代码示例

本文整理汇总了C#中NSString.GetSizeUsingAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# NSString.GetSizeUsingAttributes方法的具体用法?C# NSString.GetSizeUsingAttributes怎么用?C# NSString.GetSizeUsingAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NSString的用法示例。


在下文中一共展示了NSString.GetSizeUsingAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Print

		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);
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:57,代码来源:PrintBannerViewController.cs

示例2: CreateImage

        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 ();
            }
        }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:32,代码来源:TagChipCache.cs

示例3: ButtonTextSize

		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;
		}
开发者ID:Surfoo,项目名称:WF.Player,代码行数:11,代码来源:Measure.cs

示例4: CreateButton

 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);
 }
开发者ID:sudipnath,项目名称:ios-sdk,代码行数:15,代码来源:SideDrawerTransitions.cs

示例5: CreateButton

 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);
 }
开发者ID:tremors,项目名称:ios-sdk,代码行数:17,代码来源:SideDrawerTransitions.cs

示例6: GetImage

        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;
        }
开发者ID:KiranKumarAlugonda,项目名称:TableViewMailBox,代码行数:43,代码来源:EmailServer.cs

示例7: DrawCenteredString

 /// <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);
 }
开发者ID:HugeLawn-MiracleApps,项目名称:Xamarin-Forms-Labs,代码行数:21,代码来源:CalendarMonthView.cs

示例8: DrawDateString

		/// <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);
		}
开发者ID:Jaskomal,项目名称:Xamarin-Forms-Labs,代码行数:30,代码来源:CalendarDayView.cs

示例9: displayToastWithMessage

		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();
						 }
				);


		}
开发者ID:IanLeatherbury,项目名称:tryfsharpforms,代码行数:50,代码来源:DataMarkers.cs

示例10: Draw

        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
//.........这里部分代码省略.........
开发者ID:RecursosOnline,项目名称:c-sharp,代码行数:101,代码来源:GraphHeaderView.cs

示例11: MeasureTitle

        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;
        }
开发者ID:trongtran,项目名称:HMSegmentedControl,代码行数:19,代码来源:HMSegmentedControl.cs

示例12: updateLabelForLayer

        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);
            }
        }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:19,代码来源:XYDonutChart.cs

示例13: ReloadData

        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;
        }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:48,代码来源:BarChart.cs

示例14: UpdateImage

		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);

//.........这里部分代码省略.........
开发者ID:Surfoo,项目名称:WF.Player,代码行数:101,代码来源:BadgeImageRenderer.cs

示例15: Draw

        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();
        }
开发者ID:yingfangdu,项目名称:BNR,代码行数:97,代码来源:HypnosisView.cs


注:本文中的NSString.GetSizeUsingAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。