public void AppendIcon(IIcon icon) { var font = IconFonts.FindModuleOf(icon)?.ToUIFont(_iconText.Font.PointSize); var attrStr = new NSAttributedString($"{icon.Character}", font, _iconText.TextColor); Append(attrStr); }
public void AppendIcon(IIcon icon) { Append(icon.Character); SetSpan(new CustomTypefaceSpan(IconFonts.FindModuleOf(icon).ToTypeface(Application.Context)), Length() - 1, Length(), SpanTypes.ExclusiveInclusive); SetSpan(new ForegroundColorSpan(_iconText.TextColor), Length() - 1, Length(), SpanTypes.ExclusiveInclusive); SetSpan(new AbsoluteSizeSpan((int)_iconText.TextSize), Length() - 1, Length(), SpanTypes.ExclusiveInclusive); }
/// <summary> /// To the UI image. /// </summary> /// <param name="icon">The icon.</param> /// <param name="size">The size.</param> /// <returns></returns> public static UIImage ToUIImage(this IIcon icon, nfloat size) { var attributedString = new NSAttributedString($"{icon.Character}", new CTStringAttributes { Font = new CTFont(IconFonts.FindModuleOf(icon).FontName, size), ForegroundColorFromContext = true }); var boundSize = attributedString.GetBoundingRect(new CGSize(10000f, 10000f), NSStringDrawingOptions.UsesLineFragmentOrigin, null).Size; UIGraphics.BeginImageContextWithOptions(boundSize, false, 0f); attributedString.DrawString(new CGRect(0f, 0f, boundSize.Width, boundSize.Height)); using (var image = UIGraphics.GetImageFromCurrentImageContext()) { UIGraphics.EndImageContext(); return(image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)); } }
/// <summary> /// Create an <see cref="IconDrawable" />. /// </summary> /// <param name="context">Your activity or application context.</param> /// <param name="icon">The icon you want this drawable to display.</param> public IconDrawable(Context context, IIcon icon) { var module = IconFonts.FindModuleOf(icon); if (module is null) { throw new Java.Lang.IllegalStateException($"Unable to find the module associated with icon {icon.Key}, have you registered the module you are trying to use with IconFonts.With(...) in your Application?"); } _context = context; _icon = icon; _paint = new TextPaint { AntiAlias = true, TextAlign = Paint.Align.Center, UnderlineText = false }; _paint.SetStyle(Paint.Style.Fill); _paint.SetTypeface(module.ToTypeface(context)); }