美文网首页
swift - warnView 提醒小圆点

swift - warnView 提醒小圆点

作者: GA_ | 来源:发表于2017-03-14 15:39 被阅读74次
    //
    //  GA_WarnView.swift
    //  GA_Kingfisher
    //
    //  Created by houjianan on 2017/1/6.
    //  Copyright © 2017年 houjianan. All rights reserved.
    //
    
    import UIKit
    private let kWarnViewKey = "warnView"
    extension UIView {
        
        private var warnView: UIView? {
            set {
                objc_setAssociatedObject(self, kWarnViewKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
            }
            get {
                if let v = objc_getAssociatedObject(self, kWarnViewKey) as? UIView {
                    return v
                }
                return nil
            }
        }
        
        func addWarnView(origin: CGPoint, size: CGFloat, color: UIColor) {
            warnView = UIView()
            warnView?.tag = 201
            warnView?.frame = CGRect(x: origin.x, y: origin.y, width: size, height: size)
            warnView?.backgroundColor = color
            warnView?.layer.masksToBounds = true
            warnView?.layer.cornerRadius = size / 2
            self.addSubview(warnView!)
            
    //        self.perform(#selector(UIView.dismiss), with: self, afterDelay: 2)
        }
        
        func showWarnView(origin: CGPoint, size: CGFloat, color: UIColor) {
            addWarnView(origin: origin, size: size, color: color)
        }
        
        func dismiss() {
            if let warnView = warnView {
                warnView.removeFromSuperview()
            }
        }
        
        
    }
    

    相关文章

      网友评论

          本文标题:swift - warnView 提醒小圆点

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