0

I have 30 sec of a song being played when the play button is being played. I want a progress bar to go around the play button as the song is being played. How would I do this?

play = add[indexPath.row]
    let playButton : UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
    playButton.tag = indexPath.row
    let imageret = "playbutton"
    playButton.setImage(UIImage(named: imageret), forState: .Normal)
    playButton.frame = CGRectMake(236, 20, 100, 100)
    playButton.addTarget(self,action: "playit:", forControlEvents: UIControlEvents.TouchUpInside)
blee
  • 297
  • 4
  • 13

1 Answers1

7

I'm assuming you want something like this:

enter image description here

It is a CAShapeLayer whose path is a circle. We start with a strokeEnd of 0 and animate it up to 1. You can poll the song's progress using an NSTimer at, say, 1-second intervals and calculate how much of the song has played, and set the strokeEnd to that fraction.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • This is exactly what I needed – blee Sep 30 '15 at 03:48
  • You can use an open source such as - https://github.com/vinicius-a-ro/ios-circular-progress-bar – Shripada Sep 30 '15 at 03:55
  • That is written in objective C, any other resources with swift code? – blee Sep 30 '15 at 04:31
  • I don't see what more you need to know beyond what I already told you. I explained completely how to do it! However, it comes from my book, so you can always look at the code: https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch12p566customThermometer/ch25p840customThermometer/MyCircularProgressButton.swift – matt Sep 30 '15 at 13:56