indicator on off by string input fun
swift 2.2 and above
func activityonoff(viewcontroler:UIViewController,string:String){
let container: UIView = UIView()
let loadingView: UIView = UIView()
if string == "on"{
container.frame = viewcontroler.view.frame
container.center = viewcontroler.view.center
container.backgroundColor = UIColor.whiteColor()
container.alpha = 1
container.tag = 1
loadingView.frame = CGRectMake(0, 0, 80, 80)
loadingView.center = container.center
loadingView.backgroundColor = UIColor(red: 4/255, green: 68/255, blue: 68/255, alpha: 0.7)
loadingView.clipsToBounds = true
loadingView.layer.cornerRadius = 10
let actInd: UIActivityIndicatorView = UIActivityIndicatorView()
actInd.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
actInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
actInd.center = CGPointMake(loadingView.frame.size.width / 2,loadingView.frame.size.height / 2);
loadingView.addSubview(actInd)
container.addSubview(loadingView)
viewcontroler.view.addSubview(container)
actInd.startAnimating()
}
else{
for v in viewcontroler.view.subviews{
if v.tag == 1{
v.removeFromSuperview()
}
}
}
}
view
, you could add your own subview and place your labels there. Then you can safely remove all the subviews of that view. – Disrespect