標籤:ios swift 活動指標 uiactivityindicatorv
轉載請聲明出處:http://blog.csdn.net/jinnchang/article/details/44828021
------------------------------------------------------------------------------------------
程式碼範例
//// ViewController.swift// UIActivityIndicatorViewSample//// Created by jinnchang on 15/4/1.// Copyright (c) 2015年 Jinn Chang. All rights reserved.//import UIKitclass ViewController: UIViewController { var button1: UIButton! var button2: UIButton! var activityIndicatorView: UIActivityIndicatorView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // 定義一個顯示 activityIndicatorView 的按鈕 button1 = UIButton.buttonWithType(UIButtonType.System) as UIButton button1.frame = CGRectMake(self.view.frame.width/2 - 200, 50, 400, 50) button1.setTitle("顯示", forState: UIControlState.Normal) button1.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside) button1.tag = 1 // 定義一個隱藏 activityIndicatorView 的按鈕 button2 = UIButton.buttonWithType(UIButtonType.System) as UIButton button2.frame = CGRectMake(self.view.frame.width/2 - 200, 150, 400, 50) button2.setTitle("隱藏", forState: UIControlState.Normal) button2.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside) button2.tag = 2 // 定義一個 activityIndicatorView activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.White) activityIndicatorView.frame = CGRectMake(self.view.frame.size.width/2 - 50, 250, 100, 100) activityIndicatorView.hidesWhenStopped = true activityIndicatorView.color = UIColor.blackColor() self.view.addSubview(button1) self.view.addSubview(button2) self.view.addSubview(activityIndicatorView) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /// 按鈕響應事件 func buttonAction(sender: UIButton) { let num = sender.tag switch num { case 1: activityIndicatorView.startAnimating() case 2: activityIndicatorView.stopAnimating() default: break } }}
------------------------------------------------------------------------------------------
結果展示
------------------------------------------------------------------------------------------
結語GitHub 上項目地址:UIActivityIndicatorViewSample
文章最後更新時間:2015年4月2日09:41:40。更多資料參考:
UIActivityIndicatorView Class Reference
UIKit User Interface Catalog: Activity Indicators
論 Swift 開發入門:活動指標(UIActivityIndicatorView)