uiimageview - iOS: How to fill image with percentage -


i want fill image percentage (e.g. same rating).

  • actually showing rating image with float value.
  • depend upon float value need fill particular image.

i got result fill on image. query fill image percentage value.

my code:

- (void)viewdidload {     [super viewdidload];      _colimgview.image = [self imagenamed:@"star.png" withcolor:[uicolor redcolor]]; }  - (uiimage *)imagenamed:(nsstring *)name withcolor:(uicolor *)color {     // load image      uiimage *img = [uiimage imagenamed:name];      // begin new image context, draw our colored image onto     uigraphicsbeginimagecontext(img.size);      // reference context created     cgcontextref context = uigraphicsgetcurrentcontext();      // set fill color     [color setfill];      // translate/flip graphics context (for transforming cg* coords ui* coords     cgcontexttranslatectm(context, 0, img.size.height);     cgcontextscalectm(context, 1.0, -1.0);      // set blend mode color burn, , original image     cgcontextsetblendmode(context, kcgblendmodecolorburn);     cgrect rect = cgrectmake(0, 0, img.size.width, img.size.height);     cgcontextdrawimage(context, rect, img.cgimage);      // set mask matches shape of image, draw (color burn) colored rectangle     cgcontextcliptomask(context, rect, img.cgimage);     cgcontextaddrect(context, rect);     cgcontextdrawpath(context,kcgpathfill);      // generate new uiimage graphics context drew onto     uiimage *coloredimg = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();      //return color-burned image     return coloredimg; } 

preview image:

enter image description here

you have add overlay. overlay should under image , image should png transparency. fill overlay color in specified area can use code here: ios - fill bezierpath multiple colors based on percentage

if find free time write code you, can explain should do.


Comments