我有一个Xamarin Forms v4.2解决方案,我想在其中使用一些Font Awesome 5图标。我在正确的位置添加了Font Awesome TTF文件,我相信文件属性会根据平台正确设置。但是,当我尝试使用FA图标时,iOS和Android会正确显示,而UWP会在图标的位置显示一个正方形。我提供了App.xaml,Page.xaml和常量帮助程序文件的代码片段,以及UWP文件位置的图片以及每个平台显示的图片。我相信这与UWP找不到字体文件有关,因为其他两个平台可以完美地工作。但是我已经可以解决这个问题。
#Get screen height and width WITHOUT including the taskbar.
#This part works fine - I've tested the result and it's good.
from win32api import GetMonitorInfo, MonitorFromPoint
monitorInfo = GetMonitorInfo(MonitorFromPoint((0,0)))
workArea = monitorInfo.get("Work")
screenAvailableWidth = workArea[2]
screenAvailableHeight = workArea[3]
#Create a tkinter window
from tkinter import Tk
window = Tk()
#Set new window height & width
#--------------------------------------------
#----- HERE. This is what changed: -----
#--------------------------------------------
#Make window visible so we can get some geometry
window.update_idletasks()
#Calculate title bar and border size
titlebarHeight = window.winfo_rooty() - window.winfo_y()
borderSize= window.winfo_rootx() - window.winfo_x()
#Start with full available screen
windowWidth = screenAvailableWidth
windowHeight = screenAvailableHeight
#Adjust for title bar and borders
windowWidth = windowWidth - (borderSize * 2 )
windowHeight = (windowHeight - titlebarHeight) - borderSize
#--------------------------------------------
#Show debug info
print("")
print("screenAvailableWidth:",screenAvailableWidth,
" screenAvailableHeight:",screenAvailableHeight)
print("windowWidth:\t",windowWidth," windowHeight:\t",windowHeight)
#Set the new window to upper left corner and height &
# width of screen (after adjustment)
window.geometry("{}x{}+0+0".format(windowWidth,windowHeight))
#Show the window
window.mainloop()
图片1-iOS 图片2-UWP 图片3-Android 图片4-UWP项目文件位置
答案 0 :(得分:0)
我下载了fa-regular-400.ttf,并将其添加到Android,UWP中,并且在我这方面工作正常。
在Android Assets中添加fa-regular-400.ttf,将属性更改为AndroidAssets,还在UWP Assets中添加fa-regular-400.ttf。
在App.Xaml中创建FontFamily样式
<Application.Resources>
<ResourceDictionary>
<Style x:Key="FontAwesome5FreeRegular" TargetType="Label">
<Setter Property="FontFamily">
<Setter.Value>
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS" Value="Font Awesome 5 Free" />
<On Platform="Android" Value="fa-regular-400.ttf#Font Awesome 5 Free Regular" />
<On Platform="UWP" Value="Assets/fa-regular-400.ttf#Font Awesome 5 Free" />
</OnPlatform>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Application.Resources>
<Label
BackgroundColor="White"
FontSize="36"
HeightRequest="100"
Style="{StaticResource FontAwesome5FreeRegular}"
Text=""
TextColor="Black">
</Label>
在Label样式中使用FontAwesome5FreeRegular样式,在Android和uwp中也是如此。
您也可以查看以下文章以获取帮助。
https://www.wintellect.com/using-fontawesome5-xamarin-forms/
https://www.msctek.com/font-awesome-xamarin-forms-xaml/
关于图标unicode,请参阅: