ios - How to change ImageView dinamically in UiTableViewCell? -


i'm trying create screen android screen below in ios enter image description here

my problem, in ios circles. in ios, use imageview circles 2 png files: red_circle , green_circle. need use red circle positive values , green circle negative values, don't know how check condition in code. can me? i'm using xamarin.ios mvvmcross.

this uiviewcontroller:

public partial class myprojectsview : mvxviewcontroller<myprojectsviewmodel> {     public myprojectsview() : base("myprojectsview", null)     {     }      public override void didreceivememorywarning()     {         base.didreceivememorywarning();          // release cached data, images, etc aren't in use.     }      public async override void viewdidload()     {         base.viewdidload();           if (respondstoselector(new selector("edgesforextendedlayout")))         {             edgesforextendedlayout = uirectedge.none;         }          var source = new mvxsimpletableviewsource(tblprojects, myprojectsitem.key, myprojectsitem.key);         tblprojects.source = source;            this.createbinding(source).to<myprojectsviewmodel>(viewmodel => viewmodel.projetos).apply();         this.createbinding(lblsyncrhonizingdata).for("visibility").to<myprojectsviewmodel>(vm => vm.isprogressbarvisible).withconversion("visibility").apply();         this.createbinding(activity).for("visibility").to<myprojectsviewmodel>(vm => vm.isprogressbarvisible).withconversion("visibility").apply();         this.createbinding(lbldatasynchronized).for("visibility").to<myprojectsviewmodel>(vm => vm.isdatasynchronized).withconversion("visibility").apply();          var bounds = uiscreen.mainscreen.bounds;         var carregamento = new carregamentoios(bounds);         view.add(carregamento);          viewmodel.carregamento = carregamento;         await viewmodel.preenchelista();     }   } 

this uitableviewcell:

public partial class myprojectsitem : mvxtableviewcell {     public static readonly nsstring key = new nsstring("myprojectsitem");     public static readonly uinib nib = uinib.fromname("myprojectsitem", nsbundle.mainbundle);      protected myprojectsitem(intptr handle) : base(handle)     {         this.delaybind(() =>         {             this.createbinding(lblprojectname).to<project>(project => project.name).apply();             this.createbinding(lblpercentage).to<project>(project => project.percentcompleted).withconversion("inttopercentcompleted").apply();             this.createbinding(lblcostmoney).to<project>(project => project.cost.variation).withconversion("doublethousandtostringabbreviation").apply();             this.createbinding(lblcostdays).to<project>(project => project.schedule.variation).withconversion("inttodaysabbreviation").apply();         });               }      public static myprojectsitem create()     {         return (myprojectsitem)nib.instantiate(null, null)[0];     }         } 

i think simplest solution make use of converter switching of image color based on value i.e. if positive = red png , negative/neutral(0) = green png.

public class costcolorconverter : mvxvalueconverter<double, uiimage> {     protected override uiimage convert(double value, type targettype, object parameter, cultureinfo culture)     {         if (value > 0)             return uiimage.frombundle("images/red_circle .png");          return uiimage.frombundle("images/green_circle.png");     } } 

you need update frombundle address match images stored. add binding update images based on values viewmodel. like:

this.createbinding(imgviewcostmoney)     .for(c => c.image)     .to<project>(project => project.cost.variation)     .withconversion(new costcolorconverter())     .apply(); this.createbinding(imgviewcostdays)     .for(c => c.image)     .to<project>(project => project.schedule.variation)     .withconversion(new costcolorconverter())     .apply(); 

note, prefer using typed converter name approach can use converter name string have in question.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -