I'm hoping to use a progress bar
to denote a percentage in my App.
I'm actually building it in Spritekit using Swift, so I'm hoping to do it programmatically, without the use of a storyboard etc.
I found this awesome tutorial , but unfortunately I can't seem to add it to my GameScene
/ worldNode...
How can I create a progress bar and add it to my GameScene, inside my SKView/Gamescene (not via ViewController)?
Well, you could use UIKit to make a progress bar. UIKit, I believe, is imported with SpriteKit but if it's not you can always import it. You'd want to make the progress bar using UIProgress
class:
let prog = UIProgressView(frame: CGRectMake(your coordinates...))
//Set progress properties here (could also add a UILabel to show percentage from `progress` property
self.view.addSubview(prog)
The progress bar needs to be placed in the SKView
of the scene. You can access it via scene.view
if you don't otherwise have a handle on it.
Here's an example in a playground:
//: Playground - noun: a place where people can play
import SpriteKit
let view = SKView(frame: CGRect(x: 0, y: 0, width: 400, height: 300))
let scene = SKScene(size: view.frame.size)
view.presentScene(scene)
let progressView = UIProgressView(progressViewStyle: UIProgressViewStyle.Default)
progressView.center = CGPoint(x: 200, y: 150)
view.addSubview(progressView)
// alternately scene.view.addSubview(progressView)
progressView.progress = 0.5
view
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.