码迷,mamicode.com
首页 > 编程语言 > 详细

论 Swift 开发入门:活动指示器(UIActivityIndicatorView)

时间:2015-04-02 10:28:45      阅读:239      评论:0      收藏:0      [点我收藏+]

标签: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 UIKit

class 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)

标签:ios   swift   活动指示器   uiactivityindicatorv   

原文地址:http://blog.csdn.net/jinnchang/article/details/44828021

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!