Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
LabelRenderer on iOS sets BackgroundColor on the container, not on the UILabel (i.e. the Control property).
This makes it very difficult to successfully subclass the LabelRenderer and add things like rounded borders to it, because the container view has a different shape.
Please make sure the renderer sets properties only on the native control and not on the container UIView.
The reason for this is because the iOS UILabel does not support vertical alignment.
In order to support vertical alignment, we make the Control the minimum viable height at all times, and then align it vertically within the container itself. Unfortunately this means that if the BackgroundColor were set on the Control you would not get the expected result, so by setting it on the container you do.
I understand, and that looks at face value like an OK solution.
However, as I pointed out, subclassing the resulting control becomes quite tricky. You can't just add rounded corners to the Control property's Layer because they'll be in the wrong place.
So I took an hour or so and made a custom UILabel subclass that _does_ support vertical centring, and used that as the Control property in a renderer instead of the plain vanilla UILabel.
Here it is:
Feel free to use and/or adapt that code as required. I'm sure you can combine the ideas in that gist with the rest of the LabelRenderer logic quite easily.