2009-08-20 10 views
3

J'essaie de créer une barre de progression verticale dans mon application Cocoa, c'est-à-dire que la barre de progression devrait croître de bas en haut. J'utilise NSProgressIndicator, et je ne peux pas trouver un moyen de spécifier vertical ou horizontal. Quelqu'un peut-il me dire s'il est possible de le faire?Comment créer une barre de progression verticale dans Cocoa?

Merci, Lee

Répondre

3

Vous pouvez définir la transformation de la commande pour la faire tourner pi/2 radians (90 degrés). Cela semble être une solution commune à la plupart des gens.

+1

Merci, ça a marché! –

0

importation UIKit

classe ViewController: UIViewController {

// THis is custom Progress view 
var progessView:VerticalProgressView! 

// We can also use default progress view given by UIKIT 
var defaultProgressView:UIProgressView! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Custom Progress view 
    progessView = VerticalProgressView(frame: CGRect(x: 0, y: 160, width: 15, height: 200)) 
    progessView.center.x = self.view.center.x - 80 
    self.view.addSubview(progessView) 

    //Default Progress view 
    defaultProgressView = UIProgressView(progressViewStyle: .bar) 
    self.view.addSubview(defaultProgressView) 
} 

override func viewDidLayoutSubviews() { 

    defaultProgressView.frame = CGRect(x: self.view.center.x + 30, y: 300, width: 100, height: 300) 
    defaultProgressView.progressTintColor = UIColor.green 
    defaultProgressView.backgroundColor = UIColor.clear 
    defaultProgressView.layer.borderWidth = 0.3 
    //defaultProgressView.layer.borderColor = [UIColor.redColor] 

    // Change the width of default Progress view 
    let customWidth = CGAffineTransform(scaleX: 5.0, y: 3.0) 
    // Transform from default horizontal to vertical 
    let rotate = CGAffineTransform(rotationAngle: (CGFloat.pi/2 + CGFloat.pi)) 

    //Two transforms should be concated and applied 
    defaultProgressView.transform = rotate.concatenating(customWidth) 

} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 


override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 
    self.progessView.setProgress(progress: 0.50, animated: true) 
    UIView.animate(withDuration: 0.95) { 
     self.defaultProgressView.setProgress(0.50, animated: true) 
    } 
} 

}

Questions connexes