zoukankan      html  css  js  c++  java
  • [Xcode 实际操作]四、常用控件-(12)环形进度条控件的使用

    目录:[Swift]Xcode实际操作

    本文将演示环形进度条控件的使用。

    在项目导航区,打开视图控制器的代码文件【ViewController.swift】

     1 import UIKit
     2 
     3 class ViewController: UIViewController {
     4 
     5     //首先添加一个环形进度条对象
     6     var indicator:UIActivityIndicatorView!
     7     
     8     override func viewDidLoad() {
     9         super.viewDidLoad()
    10         // Do any additional setup after loading the view, typically from a nib.
    11         //设置根视图的背景颜色为紫色
    12         self.view.backgroundColor = UIColor.purple
    13         
    14         //初始化环形进度条,并设置环形进度条的样式为大白
    15         indicator = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.whiteLarge)
    16         //设置环形进度条中心点的位置为(160,120)
    17         indicator.center = CGPoint(x: 160, y: 120)
    18         //开始进度条动画的播放
    19         indicator.startAnimating()
    20         
    21         //将环形进度条,添加到当前视图控制器的根视图
    22         self.view.addSubview(indicator)
    23         
    24         //创建一个位置在(20,200),尺寸为(280,44)的按钮对象
    25         let button = UIButton(frame: CGRect(x: 20, y: 200,  280, height: 44))
    26         //然后设置按钮的标题文字
    27         button.setTitle("Stop", for: .normal)
    28         //设置按钮的背景颜色为橙色
    29         button.backgroundColor = UIColor.orange
    30         //接着给按钮对象,绑定点击事件
    31         button.addTarget(self, action: #selector(ViewController.stopAnimation(_:)), for: UIControl.Event.touchUpInside)
    32         
    33         //将按钮对象,添加到视图控制器的根视图
    34         self.view.addSubview(button)
    35     }
    36     
    37     //创建一个方法,用来响应按钮的点击事件
    38     @objc func stopAnimation(_ button:UIButton)
    39     {
    40         //当点击按钮时,
    41         //停止环形进度条的动画播放
    42         indicator.stopAnimating()
    43     }
    44 
    45     override func didReceiveMemoryWarning() {
    46         super.didReceiveMemoryWarning()
    47         // Dispose of any resources that can be recreated.
    48     }
    49 }
  • 相关阅读:
    JQuery中jqGrid分页实现
    给jqGrid数据行添加修改和删除操作链接(之一)
    jquery 更新了数据库后局部刷新
    JS图片另存为(转)
    RFID系统集成公司
    R语言数据文件读写
    matlab当前目录下的相对路径
    转载:勤奋在科研中究竟有多重要?
    大型网站的架构设计问题大型高并发高负载网站的系统架构
    大型网站运维探讨和心得
  • 原文地址:https://www.cnblogs.com/strengthen/p/10016930.html
Copyright © 2011-2022 走看看