ios - Change UIImageView's color by file name -
i trying change uiimageview color , color changing code works fine problem method should dynamically change image's color file name :
changing frames image :
- (ibaction)fr1:(id)sender { mainviewcont.frameimage.image = [uiimage imagenamed:@"sf1.png"]; } - (ibaction)fr2:(id)sender { mainviewcont.frameimage.image = [uiimage imagenamed:@"sf2.png"]; } changing tint color :
- (ibaction)framecolor:(uisegmentedcontrol *)sender { nsstring *imagename ; for( int = 0; < 44 ; i++ ) { imagename = [nsstring stringwithformat:@"sf%d.png",i]; switch (sender.selectedsegmentindex) { case 0: mainviewcont.frameimage.image = [tintimage imagenamed:imagename withcolor:[uicolor blackcolor]]; break; case 1: mainviewcont.frameimage.image = [tintimage imagenamed:imagename withcolor:[uicolor whitecolor]]; break; default: break; } } } now problem image's tint 44 number(last image) changes !! , when press frame 24 not recognize frame image number 24 .
in loop setting image property of uiimageview 44 times. means seeing last image. need change color of image set image.
you should add 2 instance variables viewcontroller. imagetintcolor , imagename.
you have add method named configureview loads image imagename , sets tintcolor.
in ibaction select image save name of image in imagename , call configureview. in segmentedcontrol action save selected color in imagetintcolor , call configureview.
basically this:
- (void)configureview { uiimage *image = [tintimage imagenamed:self.imagename withcolor:self.imagetintcolor]; _frame.image = image; } - (ibaction)img1:(id)sender { self.imagename = @"sf1.png"; [self configureview]; } - (ibaction)img2:(id)sender { self.imagename = @"sf2.png"; [self configureview]; } - (ibaction)img3:(id)sender { self.imagename = @"sf3.png"; [self configureview]; } - (ibaction)changecolor:(uisegmentedcontrol *)sender { nsstring *imagename ; for( int = 1; <= 3 ; i++ ) { imagename = [nsstring stringwithformat:@"sf%d.png",i]; switch (sender.selectedsegmentindex) { case 0: self.imagetintcolor = [uicolor blackcolor]; break; case 1: self.imagetintcolor = [uicolor whitecolor]; break; default: break; } } [self configureview]; }
Comments
Post a Comment