I'm new to Xamarin and was testing Xamarin features. Below is an excerpt from my toy application. As you can see, I tried in two ways to display some Chinese characters in italic.
<Label HorizontalOptions="Center" Grid.Row="2" Margin="20, 20, 20, 0"
VerticalOptions="CenterAndExpand">
<Label.FormattedText>
<FormattedString>
<Span Text="操舵室操舵室操舵室" FontSize="Medium" FontAttributes="Italic"
TextColor="#777777" />
</FormattedString>
</Label.FormattedText>
</Label>
<Label HorizontalOptions="Center" Grid.Row="3" Margin="20, 20, 20, 0" TextType="Html"
VerticalOptions="CenterAndExpand">
<![CDATA[
<div style="font-size: 14px; color: #777777; font-style: italic;">操舵室操舵室操舵室<span style="color: #277DCA;">操舵室操舵室操舵室</span></div>
]]>
</Label>
However, both the simulator and the physical device display them as normal text (not italic). Below is a snapshot of the simulator.
Why this happens and how can I make these text italic?
Below is the package versions I use.
I test your code, and the label text display Italic when using the first way, but there are some issue using second way to set Italic.
If you want to display html text in label , and set Italic, please using the following code:
<Label
HorizontalOptions="Center"
TextType="Html"
VerticalOptions="CenterAndExpand">
<![CDATA[
This is <i style="font-size: 14px; color: #777777">操舵室操舵室操舵室</i> text.
]]>
</Label>
And I don't have any issue when using the first way to set Italic , please check my screenshot:
This is my sample you can take a look:
https://github.com/CherryBu/LabelItalic-
Related
I would like to know how can I center a text with label textwrap in stack layout please.
I tried with horizontalAlignment="center", it's ok with small text (example: "hello", "test test"), but if I use textWrap on label it doesn't work...
<StackLayout v-for="(text, indexVerse) in texts"
borderRadius="5" margin="5" padding="15" row="1" col="0" horizontalAlignment="center">
<Label textWrap="true"
:text="text.content"
color="#FFFFFF"
textAlign="center"
fontSize="20"/>
</StackLayout>
The texts are set on the left and no center :
The property to set text alignment is textAlignment if its inline on the template and text-align if you are setting it through css.
Try replacing textAlign with textAlignment like the following:
<Label textWrap="true"
:text="text.content"
color="#FFFFFF"
textAlignment="center"
fontSize="20"/>
Nativescript docs say androidElevation is a valid property for the stacklayout, but is not displayed when added in my ng project. The same elevation applied to a label works fine. Is there some additional property that needs to be added?
<StackLayout margin="10" androidElevation="12">
<Label text="sample1"></Label>
<Label text="sample2"></Label>
</StackLayout>
androidElevation works only when you set a background color on the view.
<StackLayout margin="10" androidElevation="12" style="background-color: red;">
<Label text="sample1"></Label>
<Label text="sample2"></Label>
</StackLayout>
I need something like this:
But this is what I have at the moment:
.rotate {
transform: rotate(-90deg);
font-size: 16px;
color: #FFFFFF;
}
This is my code:
<StackLayout backgroundColor="#3C414B" width="12%" height="100%" horizontalAlignment="center" verticalAlignment="center" (tap)="openDrawer('Right')">
<StackLayout class="rotate" orientation="horizontal">
<Label class="fa" style="margin-right: 10px" text=""></Label>
<Label width="100%" class="" text="New Category" textwrap="false"></Label>
</StackLayout>
</StackLayout>
You will have to set the height explicitly to the width of the element, transform doesn't take care of that by default.
Or you may even consider using an image, here is a related thread from Forums.
It looks like you rotate inner <StackLayout class="rotate" ...>, but it still get width limit of outer <StackLayout width="12%" ...>
Try so:
<StackLayout class="rotate" backgroundColor="#3C414B" width="100%" height="12%" horizontalAlignment="center" verticalAlignment="center">
<StackLayout orientation="horizontal">
<Label class="fa" style="margin-right: 10px" text=""></Label>
<Label text="New Category" textwrap="false" backgroundColor="yellow"></Label>
</StackLayout>
</StackLayout>
Or try to find solution with other layout type. For example, AbsoluteLayout
<Entry PlaceHolder="Enter Username*" placeholdercolor="Black" Text={binding Username}/>
Here,The Username has to be in Black color and astrick(*)has to be in red color.Is there a way to do something like this?
Unfortunately there is no such functionality available out-of-the-box for Entry with current Xamarin.Forms version. Here is the official Entry documentation.
An easy workaround could be to move the placeholder to a separate label. In last version of Xamarin.Forms a FormattedText property was introduced on a Label. So you could split the text to several chunks while customising it:
<Label LineBreakMode="WordWrap">
<Label.FormattedText>
<FormattedString>
<Span Text="Red Bold, " TextColor="Red" FontAttributes="Bold" />
<Span Text="default, " Style="{DynamicResource BodyStyle}">
<Span.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}" />
</Span.GestureRecognizers>
</Span>
<Span Text="italic small." FontAttributes="Italic" FontSize="Small" />
</FormattedString>
</Label.FormattedText>
</Label>
More information can be found here.
I have this Xaml:
<StackLayout Spacing="0" Margin="20">
<Label Text="I would like the word" />
<Label Text="HERE" />
<Label Text="to be in a bold font and red color" />
</StackLayout>
That gives this:
I would like the word
HERE
to be in a bold font
Is there some way I can combine these labels so that the word HERE appears in bold and red color and all words appear on one line? What I am looking for is this:
I would like the word HERE to be in a bold font
Note that I'm using Xamarin.Forms but I also tagged Xamarin.iOS as I would like to know if this is possible using a renderer and wonder if it can be done in iOS?
Use FormattedText
<Label.FormattedText>
<FormattedString>
<Span Text="I would like the word " />
<Span Text="HERE" ForegroundColor="Red" FontAttributes="Bold" />
<Span Text="to be in a bold font" />
</FormattedString>
</Label.FormattedText>
If you're using Xamarin Forms you can use the FontAttributes style attribute.
<StackLayout Spacing="0" Margin="20">
<Label Text="I would like the word" />
<Label Text="HERE" />
<Label Text="to be in a bold font and red color"
FontAttributes="Bold" />
</StackLayout>