How to programmatically add a simple default loading(progress) bar in iphone app

前端 未结 18 2551
你的背包
你的背包 2020-12-12 17:16

I am using http communication in My iPhone app. I want to show a progress bar while it is loading data from server. How can I do it programmatically?

I just want a d

18条回答
  •  遥遥无期
    2020-12-12 17:50

    Swift 5.x version of @enrique7mc's Swift code:

    var indicator: UIActivityIndicatorView = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.gray)
    indicator.frame = CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0)
    indicator.center = view.center
    view.addSubview(indicator)
    indicator.bringSubviewToFront(view)
    UIApplication.shared.isNetworkActivityIndicatorVisible = true
    

    Start it with

    indicator.startAnimating()
    

    Stop it with

    indicator.stopAnimating()
    

    This adds a small ActivityIndicator (turning circle, Apple's documentation) to the middle of the screen and to the status bar. The first one will be cleared once you switch to a different ViewController, while the one in the status bar won't - you have to manually disable it.

提交回复
热议问题