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


C# CGContext.SelectFont方法代码示例

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


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

示例1: ShowCenteredTextAtPoint

		protected void ShowCenteredTextAtPoint (CGContext context, float centerX, float y, string text, int textHeight)
		{
			context.SelectFont ("Helvetica-Bold", textHeight, CGTextEncoding.MacRoman);
			context.SetTextDrawingMode (CGTextDrawingMode.Invisible);
			context.ShowTextAtPoint (centerX, y, text, text.Length);
			context.SetTextDrawingMode (CGTextDrawingMode.Fill);
			context.ShowTextAtPoint (centerX - (context.TextPosition.X - centerX) / 2, y, text, text.Length);
		}
开发者ID:GSerjo,项目名称:monotouch-samples,代码行数:8,代码来源:View.cs

示例2: MeasureStringWidth

        // TODO: Cannot use NSAttributedString in iOS5, only iOS6+
//        public static RectangleF MeasureString(SizeF sizeConstraint, string text, string fontName, float fontSize)
//        {
//            NSMutableDictionary dict = new NSMutableDictionary();
//            dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
//            NSString nsstr = new NSString(text);
//            RectangleF rect = nsstr.BoundingRectWithSize(sizeConstraint, NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
//            return rect;
//        }
        
        public static float MeasureStringWidth(CGContext context, string text, string fontName, float fontSize)
        {
			if (string.IsNullOrEmpty(text))
				return 0;

            context.SaveState();
            PointF pos = context.TextPosition;
            context.SelectFont(fontName, fontSize, CGTextEncoding.MacRoman);
            context.TextMatrix = CGAffineTransform.MakeScale(1.0f, -1.0f);
            //context.TranslateCTM(0, 20);
            context.ScaleCTM(1, -1);
            context.SetTextDrawingMode(CGTextDrawingMode.Invisible);
            context.ShowTextAtPoint(pos.X, pos.Y, text);
            PointF pos2 = context.TextPosition;
            context.RestoreState();
            
            return pos2.X - pos.X;
        }
开发者ID:pascalfr,项目名称:MPfm,代码行数:28,代码来源:CoreGraphicsHelper.cs

示例3: DrawTextAtPoint

		// Draws the specified text starting at x,y of the specified height to the context.
		protected void DrawTextAtPoint (CGContext context, float x, float y, string text, int textHeight)
		{
			// configure font
			context.SelectFont ("Helvetica-Bold", textHeight, CGTextEncoding.MacRoman);
			// set it to fill in our text, don't just outline
			context.SetTextDrawingMode (CGTextDrawingMode.Fill);
			// call showTextAtPoint
			context.ShowTextAtPoint (x, y, text, text.Length);
		}
开发者ID:Rajneesh360Logica,项目名称:monotouch-samples,代码行数:10,代码来源:Controller.cs

示例4: ShowTextAtPoint

		protected void ShowTextAtPoint (CGContext context, float x, float y, string text, int textHeight)
		{
			context.SelectFont ("Helvetica-Bold", textHeight, CGTextEncoding.MacRoman);
			context.SetTextDrawingMode (CGTextDrawingMode.Fill);
			context.ShowTextAtPoint (x, y, text, text.Length);
		}
开发者ID:rojepp,项目名称:monotouch-samples,代码行数:6,代码来源:Controller.cs

示例5: DrawText

        private void DrawText(string text, CGContext context, RectangleF bounds, bool withShadow)
        {
            // save state and transform
            context.SaveState ();
            context.TranslateCTM (0, bounds.Height);
            context.ScaleCTM (1.0f, -1.0f);

            // calculate location
            context.SelectFont("Helvetica", UIFont.LabelFontSize,CGTextEncoding.MacRoman);
            NSString t = new NSString(text);
            var font = UIFont.FromName("Helvetica", UIFont.LabelFontSize);
            var size = t.StringSize(font);
            var x = bounds.Left;
            var y = bounds.Height/2 - size.Height/2;

            // draw the shadow at an offset
            if (withShadow) {
                UIColor.FromRGB(193,193,193).SetFill();
                context.ShowTextAtPoint(x+1, y+4, text);
            }

            // draw the text
            if (_parentCell.Highlighted && !_menuItem.IsHeader)
                _headerForegroundColor.SetFill ();
            else if (_menuItem.IsHeader)
                _headerForegroundColor.SetFill ();
            else
                _foregroundColor.SetFill();
            context.ShowTextAtPoint(x, y+5, text);

            // restore context
            context.RestoreState();
        }
开发者ID:redbitdev,项目名称:socialcloud-mobile,代码行数:33,代码来源:MainMenuTableViewCell.cs


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