本文整理汇总了C#中CGContext.ShowTextAtPoint方法的典型用法代码示例。如果您正苦于以下问题:C# CGContext.ShowTextAtPoint方法的具体用法?C# CGContext.ShowTextAtPoint怎么用?C# CGContext.ShowTextAtPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGContext
的用法示例。
在下文中一共展示了CGContext.ShowTextAtPoint方法的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);
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}