Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Multi Line label with auto layout not working

JF.0444JF.0444 USMember ✭✭✭
edited September 2016 in Xamarin.iOS

Hi I have a table view set up with a custom cell. An image with two columns of labels 6 in total. One label is for an address which I would like to expand vertically when word wrapping is necessary. I would also like the width to expand with screen size so that on an iPad pro for example there isn't a giant gap of white space or wrapping when none is really necessary. All other labels have a fixed height, width, and relative position. The result I am getting is that the address is not wrapping. If I change all the bottom constraints from equal to greater than equal then they wrap properly but the ones that don't need to wrap get extra space on the bottom. The main problem is that there are a couple of interactions on the page that reloads data. So anytime the user interacts with this page for the first time you get this jarring reload where elements are resizing when there is no change in content. If the user scrolls down then back up it also fixes the problem. The label has lines set to 0 and line break mode set to word wrap.

After many hours of research I have tried every workaround I have found.
Reloading the data in ViewDidApear
Changing Compression ration
setting PreferredMaxLayoutWidth in the custom cell's LayoutSubviews as well as initialization code
Subclassing the address label and setting PreferredMaxLayoutWidth on bounds change
Calling layoutIfNeeded and or SetNeedsLayout on tableview, cell, and label

There seems to be an open bug report for ios, http://openradar.appspot.com/17799811, but its marked as closed and the workaround listed is not working for me. I have been struggling with this for quite some time. Currently I have it set to a height of 21 and truncate the tail but I would love to get this figured and out and working the way it should.

If I add

Task.Run(async () => {
await Task.Delay(1000);
InvokeOnMainThread(() => {
        tableView.ReloadData();
    });
});

It seems to work consistently but its obviously a terrible solution.

Sign In or Register to comment.