Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to alter text of label based on if the text would overflowing - in Xamarin forms

I have a UI requirement for displaying the user name list like the ones that appear on social media posts for displaying people who liked the post.

The problem in it is the overflow thing.

if it's a single user. Simply display them.

enter image description here

If it's a long list and overflows the label length then out the overflowing user names has to removed and replaced with remaining user count text.

enter image description here

Since I search through web and found no Xamarin Forms way of doing this. I am thinking of creating a custom renderer for this and using native text measuring API to figure the text to be displayed.

Android

var textSize = paint.MeasureText(this.Control.Text);

iOS

NSAttributedString nS = new NSAttributedString(txt, font: this.Control.Font);
var textSize = nS.Size;

Am I in right path? Is there any other way of doing this?

Tagged:

Best Answer

Answers

Sign In or Register to comment.