Making Sounds-Adding a duration Label

Опубликовано: 19 Июнь 2026
на канале: MilmersXcode
1,171
12

In this tutorial I teach you how to add a duration label to your music app that will let your user know what time the song is at.

Main Code - Changed slightly from the video (More efficient):

In .h:

IBOutlet UILabel *soundLabel;
(NSString *)updateLabel;

In .m:

(NSString *) updateLabel {

double currentTime = sound.currentTime;

int minutes = floor(currentTime/60);
int seconds = trunc(currentTime - minutes * 60);

NSString *belowTen = [NSString stringWithFormat:@"%i:0%i" ,minutes,seconds];
NSString *aboveTen = [NSString stringWithFormat:@"%i:%i" ,minutes,seconds];

if (seconds LESSTHANSIGN 10)
return belowTen;
else
return aboveTen;
}

in updateSlider:
soundLabel.text = [self updateLabel];

in changePosition:
soundLabel.text = [self updateLabel];

in resetSound:
soundLabel.text = @"0:00";

Twitter:   / failcakeapps  
Apple Developer Center: http://developer.apple.com/devcenter/...
Website: http://failcake.webs.com/
Channel:    / milmersxcode