Xamarin.Forms Label Renderer for Displaying many lines

I am back again with a post on Xamarin.Forms Custom Renderer. My earlier post was on the creation of a Custom Renderer for Entry.

Well, this time, we are going to solve something different which might not have been faced by many users. Sometimes, it happens that you want to display some lines of Text to the user like Read Me or just some Random text. For instance, consider the following code snippet:

<Label Text="{Binding SomeText}" HorizontalOptions="Fill">

Here, when the App is run, the text will be filled in the Label. However, if the number of lines crosses 100, the text will get clipped. In case, you want some more lines, you can always create a Custom Renderer for Label.

You can try to create something like this:

In Android

public class CustomLabelRenderer: LabelRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
    {
        base.OnElementChanged(e);
        Control.SetMaxLines(500);
    }
}

In iOS

public class CustomLabelRenderer : LabelRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {
            UILabel label = Control;
            label.Lines = 500;
        }
    }
}

Hope this helps someone.

Happy Coding!
 

Trying Xamarin.Forms Entry Renderer for Corner Radius

I am always amazed by the capability of Xamarin.Forms Custom Renderer. I wanted to try something and thought of extending the Entry Custom Renderer for Windows Phone App initially to try and provide Corner Radius for Textbox.

If you are a Windows Phone developer, then you already know the complexities. Generally, the TextBox element in Windows Phone, doesn’t have the property of CornerRadius. Corner Radius, generally provides the Curved borders, which in this case would provide for the Textbox control. Anyways, in order to provide a separate border, we generally have to nest the TextBox inside a Border element to provide the Corner Radius.

<Border Margin="5" Padding="5" BorderThickness="1" BorderBrush="Red" Background="AntiqueWhite" CornerRadius="10">
    <TextBlock Text="Lorem ipsum"/>
</Border>

Now I have tried to achieve somewhat same in Xamarin.Forms using Custom Renderers for Windows Phone.
The code is currently checked-in here.

Happy Coding!