Reputation: 73
I'm placing icons in buttons and labels but this is the result:
The icon is displayed but it changes the text. How can I display the icon without changing the text?
<Button x:Name="btnItems" Text=" Load Items" FontFamily="{StaticResource FontAwesomeSolid}" />
Upvotes: 0
Views: 578
Reputation: 2985
Button
can have Text
and one ImageSource
with FontImageSource
:
ContentLayout
sets position and spacing of image relative to text with default values shown in below XAML.
Possible position values are Left
, Right
, Top
, Bottom
.
With position values Left
or Right
text is vertically centered.
With position values Top
or Bottom
text is horizontally centered.
<Button Text="fa-list" ContentLayout="Left, 10">
<Button.ImageSource>
<FontImageSource Glyph="" FontFamily="{StaticResource FaRegular4}"/>
</Button.ImageSource>
</Button>
Label
can have one or more Span
:
<Label>
<Label.FormattedText>
<FormattedString>
<Span Text="f0A4 " />
<Span Text="" FontFamily="{StaticResource FaRegular4}" />
<Span Text=" f0A5 " />
<Span Text="" FontFamily="{StaticResource FaRegular4}" />
</FormattedString>
</Label.FormattedText>
</Label>
Upvotes: 3
Reputation: 15786
One workaround I can thought is separate the icon and text:
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" BackgroundColor="Purple">
<Button Text="" FontFamily="FontAwesome" TextColor="White" WidthRequest="25" HorizontalOptions="Center"
VerticalOptions="Center" />
<Label Text="Load Items" TextColor="White" WidthRequest="90"
HorizontalOptions="Center"
VerticalOptions="Center" />
</StackLayout>
Upvotes: 0
Reputation: 3356
I believe the simplest way is to use button Image instead. Download the Icon and add it to your Resources folder in iOS and Drawable in Android.
And then use it in your button like this:
<Button Text="Edit" ImageSource="edit_icon" />
BTW, you need to change the button's font to something else or just leave the default.
Upvotes: 0