첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.22MB

▶ FontModel.cs

namespace TestProject;

/// <summary>
/// 폰트 모델
/// </summary>
public class FontModel
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Property
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 아이콘 - Icon

    /// <summary>
    /// 아이콘
    /// </summary>
    public ImageSource Icon { get; set; }

    #endregion
    #region 글리프 - Glyph

    /// <summary>
    /// 글리프
    /// </summary>
    public string Glyph { get; set; }

    #endregion
}

 

728x90

 

▶ FontCollection.cs

using System.Globalization;
using System.Text.RegularExpressions;

namespace TestProject
{
    /// <summary>
    /// 폰트 컬렉션
    /// </summary>
    public class FontCollection : List<FontModel>
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - FontCollection()

        /// <summary>
        /// 생성자
        /// </summary>
        public FontCollection()
        {
            for(int i = 0xf0ff ; i < 0xf3aa; i++)
            {
                string escapedUnicode    = "\\u" + i.ToString("x4");
                string nonEscapedUnicode = GetNonEscapedUnicodeString(escapedUnicode);

                FontImageSource fontImageSource = new FontImageSource();

                fontImageSource.Color      = Colors.Blue;
                fontImageSource.FontFamily = "ionicons";
                fontImageSource.Glyph      = nonEscapedUnicode;

                Add(new FontModel { Icon = fontImageSource, Glyph = escapedUnicode });
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 비 이스케이프 유니코드 문자열 구하기 - GetNonEscapedUnicodeString(sourceEscapedUnicodeString)

        /// <summary>
        /// 비 이스케이프 유니코드 문자열 구하기
        /// </summary>
        /// <param name="sourceEscapedUnicodeString">소스 이스케이프 유니코드 문자열</param>
        /// <returns>비 이스케이프 유니코드 문자열</returns>
        private string GetNonEscapedUnicodeString(string sourceEscapedUnicodeString)
        {
            return Regex.Replace
            (
                sourceEscapedUnicodeString,
                @"\\u(?<Value>[a-zA-Z0-9]{4})",
                m =>
                {
                    return ((char)int.Parse(m.Groups["Value"].Value, NumberStyles.HexNumber)).ToString();
                }
            );
        }

        #endregion
    }
}

 

300x250

 

▶ MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="TestProject.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:TestProject">
    <ContentPage.Resources>
        <local:FontCollection x:Key="FontCollectionKey" />
    </ContentPage.Resources>
    <ScrollView Margin="20">
        <StackLayout BindableLayout.ItemsSource="{StaticResource FontCollectionKey}">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <StackLayout Orientation="Horizontal">
                        <Image
                            VerticalOptions="Center"
                            WidthRequest="32"
                            HeightRequest="32"
                            Source="{Binding Icon}" />
                        <Label
                            Margin="10,0,0,0"
                            VerticalOptions="Center"
                            Text="{Binding Glyph}" />
                    </StackLayout>
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </StackLayout>
    </ScrollView>
</ContentPage>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요