【发布时间】:2017-09-06 01:36:36
【问题描述】:
我开发了一个 Xamarin.Forms 应用程序,我正在寻找一个 图标,让我可以显示活动是否免费强>...
由于我没有在 FontAwesome、Ionicons 或 Material 等常用字体图标中找到任何内容,因此我决定创建一个带有标签的“自定义”图标。
为此,我选择了:
- 对于付费活动:细圈中的“€”符号
- 对于免费活动:“€”符号被反斜杠 (“\”) 围成一个细圈
第一种情况没有问题:
<Grid Margin="1,0"
ColumnSpacing="0"
RowSpacing="0"
HeightRequest="14"
>
<Label
Text="{ x:Static local:FontAwesomeFont.CircleThin }"
Style="{ StaticResource FontIcon }"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
Opacity="1"
FontSize="14"
TextColor="{ DynamicResource BaseTextColor }" />
<Label
Text="{ x:Static local:FontAwesomeFont.Euro }"
FontSize="8"
Style="{ StaticResource FontIcon }"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
TextColor="{ DynamicResource BaseTextColor }" />
</Grid>
但是第二种情况比较困难,因为iOS和Android的渲染是有区别的:
<Grid Margin="1,0"
ColumnSpacing="0"
RowSpacing="0"
HeightRequest="14"
>
<Label
Text="{ x:Static local:FontAwesomeFont.CircleThin }"
Style="{ StaticResource FontIcon }"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
Opacity="1"
FontSize="14"
TextColor="{ DynamicResource BaseTextColor }" />
<!-- Backslash -->
<Label
Text="\"
Style="{ StaticResource FontIcon }"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
Rotation="-22"
TextColor="{ DynamicResource BaseTextColor }"
FontAttributes="Bold"
>
<Label.FontSize>
<artina:OnOrientationDouble>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="iOS">13</On>
<On Platform="Android">12</On>
</OnPlatform>
</Label.FontSize>
<Label.Margin>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="Android">0,0,0,0.5</On>
<On Platform="iOS">0.5,0,0,1.5</On>
</OnPlatform>
</Label.Margin>
</Label>
<Label
Text="{ x:Static local:FontAwesomeFont.Euro }"
FontSize="8"
Style="{ StaticResource FontIcon }"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
TextColor="{ DynamicResource BaseTextColor }" />
</Grid>
这样,我得到一个正确但不完美的结果:
- 在 Android 上:
(“Gratuit”代表免费图标)
- 在 iOS 上:
(“Gratuit”代表免费图标)
另外,如果我需要为这个图标使用更大的尺寸,我必须重新定义反斜杠的每个参数。
有没有更简洁的方法来实现这一点?
【问题讨论】:
标签: xamarin.ios xamarin.android xamarin.forms icons label