So i have this slider in my view and that has a max of 13 and a min of 1. Dependent on how you move the slider the number changes and can be shown on a label that shows the current number the slider is on.
I want to be able to change the int from the slider into a string; so if the progress of the slider is 13 i want the label to read “A+”, 12 with “A” 11 with “A-” and so on.
Without having to make 13 “if” statements because i have more than one slider, is there a way to make a method that checks the progress of the slider then converts the number to the desired letter grade?
here is my code for one of the sliders
-(IBAction)sliderChanged:(id)sender{
UISlider *slider = (UISlider *)sender;
int progress = (int)roundf(slider.value);
c1Grade.text = [NSString stringWithFormat:@"%d",progress];
}
// c1Grade is the label next to the slider showing the progress
Make an array of strings, and place the description at the index the description represents:
@"A+"would be at index 13,"A"at index 12, and so on.Since
gradeDescriptionsarray never changes, you can initialize it once, and store in a static variable or an ivar.