本文整理汇总了C#中UILabel.ToNativeImage方法的典型用法代码示例。如果您正苦于以下问题:C# UILabel.ToNativeImage方法的具体用法?C# UILabel.ToNativeImage怎么用?C# UILabel.ToNativeImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UILabel
的用法示例。
在下文中一共展示了UILabel.ToNativeImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddText
/// <summary>
/// Adds the text.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="text">The text.</param>
/// <param name="point">The point.</param>
/// <param name="font">The font.</param>
/// <param name="color">The color.</param>
/// <param name="alignment">The alignment.</param>
/// <returns>UIImage.</returns>
public static UIImage AddText(
this UIImage image,
string text,
CGPoint point,
UIFont font,
UIColor color,
UITextAlignment alignment = UITextAlignment.Left)
{
//var labelRect = new RectangleF(point, new SizeF(image.Size.Width - point.X, image.Size.Height - point.Y));
var h = text.StringHeight(font, image.Size.Width);
var labelRect = new CGRect(point, new CGSize(image.Size.Width - point.X, h));
var label = new UILabel(labelRect)
{
Font = font,
Text = text,
TextColor = color,
TextAlignment = alignment,
BackgroundColor = UIColor.Clear
};
var labelImage = label.ToNativeImage();
using (var context = image.Size.ToBitmapContext())
{
var rect = new CGRect(new CGPoint(0, 0), image.Size);
context.DrawImage(rect, image.CGImage);
context.DrawImage(labelRect, labelImage.CGImage);
context.StrokePath();
return UIImage.FromImage(context.ToImage());
}
}