本文整理汇总了C#中MonoMac.Foundation.NSString.BoundingRectWithSize方法的典型用法代码示例。如果您正苦于以下问题:C# NSString.BoundingRectWithSize方法的具体用法?C# NSString.BoundingRectWithSize怎么用?C# NSString.BoundingRectWithSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoMac.Foundation.NSString
的用法示例。
在下文中一共展示了NSString.BoundingRectWithSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MeasureString
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;
}
示例2: DrawText
public static void DrawText(RectangleF rect, float x, float y, string text, string fontName, float fontSize, NSColor fontColor)
{
NSMutableDictionary dict = new NSMutableDictionary();
dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
dict.Add(NSAttributedString.ForegroundColorAttributeName, fontColor);
NSString nsstr = new NSString(text);
RectangleF rectBounds = nsstr.BoundingRectWithSize(new SizeF(rect.Width, rect.Height), NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
rectBounds.X = rect.X + x;
rectBounds.Y = rect.Y + y;
nsstr.DrawString(rectBounds, NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
}