iOS学习九之UIActivityIndicatorView

UIActivityIndicatiorView被称为活动指示器控件,通常用于加载复杂数据的视图时使用。在加载等待时间中给用户一些界面活动的指示,不至于出现使用户感觉到界面卡死的假象。

添加以下代码,即可完成此功能

    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.

        //设置屏幕背景色为绿色

        self.view.backgroundColor = UIColor.green

       //初始化控件风格,一共有3有风格,可供使用 whiteLarge 大尺寸白色风格/white 白色风格/gray 灰色风格

        let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)

        indicator.center = CGPoint(x:self.view.frame.size.width/2, y:self.view.frame.size.height/2)

        //设置活动指示器的颜色,活动指示器的背景色不属于设置的范围,只有动态变化的部分的颜色会受此属性的影响

        indicator.color = UIColor.white

        self.view.addSubview(indicator)

        //指示器开始转动 stopAnimating 停止转动

        indicator.startAnimating()

   }

猜你喜欢

转载自www.cnblogs.com/minminjy123/p/9824609.html
今日推荐