Call me politically correct if you like, but please remember that not everybody in these forums is male. The way you start your post can easily alienate a number of people who would otherwise answer questions.
@EsamSherif said:
Label's "LineHeight" works on iOS and UWP but not android
EsamSherif is correct in that Label's LineHeight does not seem to currently work on Android. Today I found a work around utilising Span to the same effect without requiring any kind of native code.
<!-- This doesn't work on Android but works on all other platforms. -->
<Label Text="Text goes here!"
LineHeight="1.2" />
<!-- This works on all platforms with no need for any native implementation. -->
<Label LineBreakMode="WordWrap">
<Label.FormattedText>
<FormattedString>
<Span Text="Text goes here!"
LineHeight="1.2" />
</FormattedString>
</Label.FormattedText>
</Label>
This works for me! Let me know if it works for you.
How can i find the right value for LineHeight? I want a LineHeight of 22pt, but in the docs it just says "The multiplier to apply to the default line height when displaying text", but not what the default value is. Where can i find it?
@Khosrou said:
Im sure that works, but Im running XF 2.5 guys
The LineHeight property is only supported in 3.2.
You would need to implement it natively in older versions but sadly I can't help with that sorry!
@Khosrou - Xamarin.Forms is open source, so you could look at the latest source code and pick out the bits that you would need to put in custom renderers to get the same result using XF 2.5
@JFMG said: @JohannesH
why not simply put a breakpoint or a print message in your code behind file?
Your XAML:
<Label
x:Name="MyLabel"
Text="My Text" />
In your code behind:
System.Diagnostics.Debug.WriteLine($"Line height of MyLabel: {MyLabel.LineHeight}")
Hey JFMG, thanks for the response, but i think you got my question wrong. My problem is: I got an Zeplin/Sketch Screen and it tells me the LineHeight is 24pt. Now LineHeight only gives the ability to set a multiplier that is applied to the "default line height" and i don't know where to get this value.
@JohannesH
That is a problem of Zeplin. Theoretically, you can display the source code for the label in Swift or AXML. Then you will see the line height multiplier. At least that is possible with InVision.
I was using Xamarin Forms 2.5 and upgraded to 3.2.839982 and although I get the LineHeight property now, it still doesn't render correctly on Android. As @BradNotBread mentioned, using FormattedText seemed to fix it on Android.
Does anyone know if this has been fixed in more recent versions of Xamarin Forms?
@Hayden_Hancock said:
I was using Xamarin Forms 2.5 and upgraded to 3.2.839982 and although I get the LineHeight property now, it still doesn't render correctly on Android. As @BradNotBread mentioned, using FormattedText seemed to fix it on Android.
Does anyone know if this has been fixed in more recent versions of Xamarin Forms?
Looking at the official Xamarin Forms Github repository this issue was marked as closed for 3.2 but that clearly isn't the case. Perhaps it would just be worth trying in the latest release. Otherwise it would be great to get an official response on why this issue is still present and when we can expect a fix.
@JFMG said: @JohannesH
why not simply put a breakpoint or a print message in your code behind file?
Your XAML:
<Label
x:Name="MyLabel"
Text="My Text" />
In your code behind:
System.Diagnostics.Debug.WriteLine($"Line height of MyLabel: {MyLabel.LineHeight}")
Hey JFMG, thanks for the response, but i think you got my question wrong. My problem is: I got an Zeplin/Sketch Screen and it tells me the LineHeight is 24pt. Now LineHeight only gives the ability to set a multiplier that is applied to the "default line height" and i don't know where to get this value.
As far as I can tell this is still a problem. Xamarin Forms let's you set a multiplier on the default lineheight. But it doesn't tell you what this height is!
@JFMG said: @JohannesH
why not simply put a breakpoint or a print message in your code behind file?
Your XAML:
<Label
x:Name="MyLabel"
Text="My Text" />
In your code behind:
System.Diagnostics.Debug.WriteLine($"Line height of MyLabel: {MyLabel.LineHeight}")
Hey JFMG, thanks for the response, but i think you got my question wrong. My problem is: I got an Zeplin/Sketch Screen and it tells me the LineHeight is 24pt. Now LineHeight only gives the ability to set a multiplier that is applied to the "default line height" and i don't know where to get this value.
As far as I can tell this is still a problem. Xamarin Forms let's you set a multiplier on the default lineheight. But it doesn't tell you what this height is!
A problem in Xamarin Form 4.2.0 or 4.3.0 ? the label renderer is pretty broken in Forms 4.3.0
Ah. We're on 4.3.0 at the moment. But an update is available. I'll need to update soon.
But no, the problem I'm referring to is as @JohannesH said. We use Zeplin, and InVision which provide line heights of say, 30. But Xamarin Forms deals in multipliers. What is this a multiplier of? The Fontsize?
So With a font size of 25px and a lineheight of 30px, I'd apply a lineheight multiplier of 1.2?
Answers
Do you want to make the text bigger or just have more empty space? If you want bigger text, change the FontSize property of the Label. If you want more empty space see https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/margin-and-padding
Call me politically correct if you like, but please remember that not everybody in these forums is male. The way you start your post can easily alienate a number of people who would otherwise answer questions.
https://github.com/xamarin/Xamarin.Forms/issues/1734
It actually doesn't work. I tried it today.
Label's "LineHeight" works on iOS and UWP but not android
EsamSherif is correct in that Label's LineHeight does not seem to currently work on Android. Today I found a work around utilising Span to the same effect without requiring any kind of native code.
This works for me! Let me know if it works for you.
Im sure that works, but Im running XF 2.5 guys
The LineHeight property is only supported in 3.2.
You would need to implement it natively in older versions but sadly I can't help with that sorry!
How can i find the right value for LineHeight? I want a LineHeight of 22pt, but in the docs it just says "The multiplier to apply to the default line height when displaying text", but not what the default value is. Where can i find it?
@JohannesH
why not simply put a breakpoint or a print message in your code behind file?
Your XAML:
In your code behind:
@Khosrou - Xamarin.Forms is open source, so you could look at the latest source code and pick out the bits that you would need to put in custom renderers to get the same result using XF 2.5
Hey JFMG, thanks for the response, but i think you got my question wrong. My problem is: I got an Zeplin/Sketch Screen and it tells me the LineHeight is 24pt. Now LineHeight only gives the ability to set a multiplier that is applied to the "default line height" and i don't know where to get this value.
@JohannesH
That is a problem of Zeplin. Theoretically, you can display the source code for the label in Swift or AXML. Then you will see the line height multiplier. At least that is possible with InVision.
I was using Xamarin Forms 2.5 and upgraded to 3.2.839982 and although I get the LineHeight property now, it still doesn't render correctly on Android. As @BradNotBread mentioned, using FormattedText seemed to fix it on Android.
Does anyone know if this has been fixed in more recent versions of Xamarin Forms?
Looking at the official Xamarin Forms Github repository this issue was marked as closed for 3.2 but that clearly isn't the case. Perhaps it would just be worth trying in the latest release. Otherwise it would be great to get an official response on why this issue is still present and when we can expect a fix.
I fixed it by upgrading XF!
It seems it is fixed , I tested it today on XF 4.2.0 and it worked on Android also
As far as I can tell this is still a problem. Xamarin Forms let's you set a multiplier on the default lineheight. But it doesn't tell you what this height is!
A problem in Xamarin Form 4.2.0 or 4.3.0 ? the label renderer is pretty broken in Forms 4.3.0
Ah. We're on 4.3.0 at the moment. But an update is available. I'll need to update soon.
But no, the problem I'm referring to is as @JohannesH said. We use Zeplin, and InVision which provide line heights of say, 30. But Xamarin Forms deals in multipliers. What is this a multiplier of? The Fontsize?
So With a font size of 25px and a lineheight of 30px, I'd apply a lineheight multiplier of 1.2?
Yes.
Btw: In InVision you can display the source code for the label in Swift or AXML. Then you will see the line height multiplier for iOS and Android.
What exactly is broken?
https://github.com/xamarin/Xamarin.Forms/issues/8520
@JFMG I realise now you already posted this exact same answer. It is the correct answer to @JohannesH's question! Thank you.
Yes, this one is awkward. Thanks for bringing it to my attention.