Bug 39310 - iOS text changing issues when using custom fonts
Summary: iOS text changing issues when using custom fonts
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.0.0
Hardware: PC Windows
: Low minor
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-03-02 21:52 UTC by Alma Jensen
Modified: 2016-08-18 18:02 UTC (History)
5 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:


Attachments
demo of issue, works correctly on Android (440.39 KB, application/x-zip-compressed)
2016-03-02 21:52 UTC, Alma Jensen
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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.

Related Links:
Status:
RESOLVED ANSWERED

Description Alma Jensen 2016-03-02 21:52:10 UTC
Created attachment 15230 [details]
demo of issue, works correctly on Android

When using a custom font that was generated off of Fontello.com to create icons I found on iOS if I change the app text, or the color that the icon changes to a box with a ? in it in iOS.  On Android I can change the font color and icon with no problem.  Initial loading of the icon or setting of the color however does work on iOS.
Comment 1 Jason Smith [MSFT] 2016-03-10 19:43:33 UTC
I can confirm the same behavior but this is not caused by Forms directly. Will look for workaround
Comment 2 Alma Jensen 2016-03-31 21:48:35 UTC
The work around I found was to create different labels for each different state of the label, and change the visibility of the label based on what I want to display.  I requires a lot of extra code though for something as mudane as changing text.
Comment 3 Rob DeRosa 2016-04-07 21:32:22 UTC
I was unable to reproduce this issue in Xcode or Xamarin.iOS. Seems to only occur when the text changes on a button click event. Attempted to reproduce duplo steps but unable to find the culprit.
Comment 4 Samantha Houts [MSFT] 2016-08-18 18:01:58 UTC
@Alma,

I think the best solution for this issue is if you make a slight adjustment to your iOS custom renderer:

protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
		{
			base.OnElementChanged(e);

			var myFont = UIFont.FromName("fontello", Control.Font.PointSize);
			Control.Font = myFont;
			Element.FontFamily = myFont.FamilyName;
		}

The difference is simply setting the Element.Fontfamily to the name of your custom font. 

In the core LabelRenderer for iOS, we need to reapply the font every time we change the Text, TextColor, etc., and we use the Font property on the Element to do this. If the Font on the Element doesn't match what is on the Control, then whatever was on the Control will be overridden. In your custom renderer, you're updating the Font on the Control, but the Element doesn't know about it. If you update the Element's FontFamily property, then your custom font will stay applied when you change the Text or TextColor.

Please let me know if you have any questions or further issues with this. Thank you!