2016-03-30 3 views
0

Bonjour Je veux montrer un UIActivityIndicatorView sur mon UIViewController exactement comme ceComment ajouter fond noir derrière le UIActivityIndicatorView

enter image description here

Comment puis-je dessiner un UIViewIndicator comme cette image ci-dessus

J'ai essayé ce

func showIndicatorView(){ 

     let loadingIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50)) 
     loadingIndicator.layer.cornerRadius = 05 

     loadingIndicator.opaque = false 
     loadingIndicator.backgroundColor = UIColor(white: 0.0, alpha: 0.6) 
     loadingIndicator.center = self.view.center; 
     loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray 
     loadingIndicator.color = UIColor.whiteColor() 
     loadingIndicator.startAnimating() 
     self.view.addSubview(loadingIndicator) 


    } 

Répondre

2

Vous pourriez le mettre dans une autre vue qui a une couleur de fond noire. Quelque chose comme ça. Vous pouvez également ajouter l'étiquette "Chargement ..." dans cette vue si vous en avez besoin.

func showIndicatorView(){ 

    let loadingIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50)) 
    let backgroundView = UIView() 

    backgroundView.layer.cornerRadius = 05 
    backgroundView.clipsToBounds = true 
    backgroundView.opaque = false 
    backgroundView.backgroundColor = UIColor(white: 0.0, alpha: 0.6) 

    loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray 
    loadingIndicator.color = UIColor.whiteColor() 
    loadingIndicator.startAnimating() 

    let loadingLabel = UILabel() 
    loadingLabel.text = "Loading..." 
    let textSize: CGSize = loadingLabel.text!.sizeWithAttributes([NSFontAttributeName: loadingLabel.font ]) 

    loadingLabel.frame = CGRectMake(50, 0, textSize.width, textSize.height) 
    loadingLabel.center.y = loadingIndicator.center.y 

    backgroundView.frame = CGRectMake(0, 0, textSize.width + 70, 50) 
    backgroundView.center = self.view.center; 

    self.view.addSubview(backgroundView) 
    backgroundView.addSubview(loadingIndicator) 
    backgroundView.addSubview(loadingLabel) 
} 
+0

Oui j'ai besoin le chargement .. aussi ... pourriez-vous s'il vous plaît ajouter que aussi bien dans votre code – hellosheikh

+0

Eh bien, je pourrais mettre aussi, mais. .. Utilisez-vous XIBs ou storyboard? C'est beaucoup plus facile et plus propre de le faire ici et pas du code. – Jelly

+0

J'utilise le storyboard – hellosheikh