//
// 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()
}
}
}
网友评论