0

So I am using UISlider for an Audio Player's scrubber. What I am attempting to do is update a label whenever a UISlider's value is changed so that it can properly display the current audio's time elapsed in minutes and seconds. Here is my current code:

- (IBAction)valueChanged:(id)sender {
    if (!self.scrubbing) {
        [[CRAudioUtility sharedUtility]seekToTime:self.progressSlider.value];
        NSInteger value    = [CRAudioUtility sharedManager].currentPlaybackTime;
        NSInteger minutes    = value / 60;
        NSInteger seconds = value % 60;

        NSString *time_stamp = [NSString stringWithFormat:@"%d hours:%d minutes",minutes,seconds];
        [self.progressSlider setAccessibilityValue:time_stamp];
        self.progressSliderLabel.text = [NSString stringWithFormat:@"%d:%d minutes",minutes,seconds;

    }
}

Audio items may or may not be longer than an hour, and the length may be more than one hour.

Since the accessibilityLabel is announced, I need to ensure that the word "hour" is announced properly in their singular or plural format. What kind of solutions can I do to handle this case?

4

1 回答 1

1

我可以采取什么样的解决方案来处理这种情况?

似乎您只想分别考虑各种可能性:

if (minutes > 120) {
    time_stamp = [NSString stringWithFormat:@"%d hours:%d minutes", minutes / 60, minutes % 60];
}
else if (minutes > 60) {
    time_stamp = [NSString stringWithFormat:@"1 hour:%d minutes", minutes % 60];
}
else {
    time_stamp = [NSString stringWithFormat:@"%d:%d minutes", minutes, seconds];
}
于 2014-05-28T18:35:13.290 回答