Set the font line height of a Xamarin.Forms Label -
i have xamarin.forms label showing several lines of text , increase line height make text more readable.
the font properties available on label control , on span controls seem limited font face, size , style.
how can change line height?
you'll need custom control , render can inherit existing ones , handle additional properties. ios (idk android) can use
// goes in forms project public class customlabel : label{ // make bindable, shortened simplicity here public double lineheight {get;set;} } // goes in ios project, 1 in android project // notice attribute before namespace [assembly: exportrendererattribute (typeof(customlabel), typeof(customlabelrenderer))] namespace mynamespace{ public class customlabelrenderer: labelrenderer protected override void onelementchanged (elementchangedeventargs<frame> e){ base.onelementchanged(e); // sample only; expand, validate , handle edge cases needed ((uilabel)base.control).font.lineheight = ((customlabel)this.element).lineheight; } // if property bindable can handle changes in method: // protected override void onelementpropertychanged (object sender, system.componentmodel.propertychangedeventargs e) }
as far ios (idk if android has feature) can use uiappearance of uilabel increase line height throughout app, in lines of:
uilabel.appearance.font.lineheight = 20f;
Comments
Post a Comment