美文网首页
自定义加载控件

自定义加载控件

作者: ZhouMac | 来源:发表于2016-06-13 10:50 被阅读33次

Busy.swift

import UIKit

class Busy : UIView {
    private var blur = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Dark))
    private var spinner = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.WhiteLarge)
    var isActive: Bool = false
    
    override init (frame : CGRect) {
        super.init(frame : frame)
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("This class does not support NSCoding")
    }
    
    func startActivity() {
        let x = UIScreen.mainScreen().bounds.width/2
        let y = UIScreen.mainScreen().bounds.height/2
        
        blur.frame = CGRectMake(100, 100, 150, 150)
        blur.layer.cornerRadius = 10
        blur.center = CGPoint(x: x, y: y)
        blur.clipsToBounds = true
        
        spinner.frame = CGRectMake(0, 0, 50, 50)
        spinner.hidden = false
        spinner.center = CGPoint(x: x, y: y)
        spinner.startAnimating()
        
        super.addSubview(blur)
        super.addSubview(spinner)
        isActive = true
    }
    
    func stopActivity() {
        blur.removeFromSuperview()
        spinner.removeFromSuperview()
        isActive = false
    }
}


ViewController.swift

import UIKit

class ViewController: UIViewController {
    var test:Busy!

    override func viewDidLoad() {
        super.viewDidLoad()
        test=Busy()
    }

    @IBAction func toggle(sender: AnyObject) {
        if test.isActive {
            test.stopActivity()
            test.removeFromSuperview()
            print("Stopping")
        } else {
            test.startActivity()
            self.view.addSubview(test)
            print("Starting")
        }
    }

}

相关文章

  • 自定义View仿抖音视频加载BufferLineView

    自定义View仿抖音视频加载BufferLineView 自定义视频选帧控件 自定义View 视频截取控件 自定义动画线

  • 自定义视频选帧控件

    自定义View仿抖音视频加载BufferLineView 自定义视频选帧控件 自定义View 视频截取控件 项目中...

  • 自定义View 视频截取控件

    自定义View仿抖音视频加载BufferLineView 自定义视频选帧控件 自定义View 视频截取控件 抖音最...

  • UI-Xib

    Xib的加载 方法1 方法2 自定义控件view的步骤 新建自定义控件类 修改xib中view的类名 封装xib的...

  • IOS -- cell解决重用机制

    类似微博自定义cell添加图片,通常会导致图片重用 解决方法:手动懒加载图片控件,然后在加载图片之前先清除图片控件...

  • UIView

    view的封装 Xib和storyboard对比 Xib的加载 使用xib自定义view的步骤 l新建自定义控件类...

  • Android自定义控件

    Android自定义控件 自定义XML文件所需要的布局文件,在构造器中加载 在values目录下新建attrs,添...

  • 自定义加载控件

    Busy.swift ViewController.swift

  • ios14的坑

    自定义cell控件要加载到contentView上,否则被覆盖!2.UIDatePicker增加了pickerSt...

  • 组合控件2——海贼王选项菜单

    之前的自定义控件——初识自定义控件,我们了解到了自定义控件分为三种,自制控件,组合控件,拓展控件。而我们在自制控件...

网友评论

      本文标题:自定义加载控件

      本文链接:https://www.haomeiwen.com/subject/cxdydttx.html