xamarin - How can I create a custom TableView that will allow me to specify footer height and text and space out the text just like in the iOS settings page? -
i saw example:
xamarin forms - how create custom render give tablesection default ios footer?
it 75% of looking code:
using coregraphics; using foundation; using uikit; using xamarin.forms; using xamarin.forms.platform.ios; [assembly: exportrenderer(typeof(tableview), typeof(japanese.ios.tableviewcustomrenderer))] namespace japanese.ios { public class tableviewcustomrenderer : tableviewrenderer { uitableview tableview; protected override void onelementchanged(elementchangedeventargs<tableview> e) { base.onelementchanged(e); if (control == null) return; var tableview = control uitableview; var formstableview = element tableview; tableview.weakdelegate = new customfootertableviewmodelrenderer(formstableview); } void current_propertychanged(object sender, system.componentmodel.propertychangedeventargs e) { } private class customfootertableviewmodelrenderer : tableviewmodelrenderer { public customfootertableviewmodelrenderer(tableview model) : base(model) { } public override nfloat getheightforfooter(uitableview tableview, nint section) { return 10; } public override string titleforfooter(uitableview tableview, nint section) { return "this title given section"; } } } }
1. able extend tableview able put in xaml way set or leave unset footer text , height. like:
<exttableview footertext="abc" footerheight="50". ..
2. experiments code above tried hardcoding in text , realize there no spacing set. find out if there way set spacing , font appears in ios settings pages?
could suggest how go creating looking guess exttableview class can accept additional arguments.
as hankide said , provide more details.
- however able extend tableview able put in xaml way set or leave unset footer text , height.
create mytableview inherits tableview
public class mytableview : tableview { public static readonly bindableproperty footerheightproperty = bindableproperty.create("footerheight", typeof(string), typeof(mytableview), ""); public string footerheight { { return (string)getvalue(footerheightproperty); } set { setvalue(footerheightproperty, value); } } public static readonly bindableproperty footertextproperty = bindableproperty.create("footertext", typeof(string), typeof(mytableview), ""); public string footertext { { return (string)getvalue(footertextproperty); } set { setvalue(footertextproperty, value); } } }
get value set in xmal , assign them customfootertableviewmodelrenderer
protected override void onelementchanged(elementchangedeventargs<tableview> e) { base.onelementchanged(e); if (control == null) return; var tableview = control uitableview; var formstableview = element mytableview; customfootertableviewmodelrenderer render = new customfootertableviewmodelrenderer(formstableview); render.height = float.parse(formstableview.footerheight); render.text = formstableview.footertext; tableview.weakdelegate = render; } private class customfootertableviewmodelrenderer : tableviewmodelrenderer { public float height { get; set; } public string text { get; set; } public customfootertableviewmodelrenderer(tableview model) : base(model) { } public override uiview getviewforfooter(uitableview tableview, nint section) { uiview view = new uiview(new cgrect(0, 0, tableview.frame.width, 50)); view.backgroundcolor = uicolor.gray; uilabel label = new uilabel(); label.frame = new cgrect(0, 0, tableview.frame.width, height); label.backgroundcolor = uicolor.red; label.text = text; label.font = uifont.systemfontofsize(15); view.add(label); return view; } public override nfloat getheightforfooter(uitableview tableview, nint section) { return 50; } }
usage:
<local:mytableview footerheight="20" footertext="abc"> <tableroot> <tablesection> <textcell text="22222" ></textcell> </tablesection> </tableroot> </local:mytableview>
from experiments code above tried hardcoding in text , realize there no spacing set. find out if there way set spacing , font appears in ios settings pages?
you override method getviewforfooter
change defalut style of footer,find in code above .
my test :
wiki
Comments
Post a Comment