p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #1e9421; background-color: #ffffff }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #c42275; background-color: #ffffff }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #000000; background-color: #ffffff }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #000000; background-color: #ffffff; min-height: 20.0px }
span.s1 { color: #000000 }
span.s2 { color: #6122ae }
span.s3 { color: #c42275 }
span.s4 { color: #3e1e81 }
span.s5 { color: #703daa }
//uiview的扩展
extension UIView{
func getFirstViewController()->UIViewController?{
for view in sequence(first: self.superview, next: {$0?.superview}){
if let responder = view?.next{
if responder.isKind(of: UIViewController.self){
return responder as? UIViewController
}
}
}
return nil
}
}
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #1e9421; background-color: #ffffff }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #000000; background-color: #ffffff }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #294c50; background-color: #ffffff }
span.s1 { color: #000000 }
span.s2 { color: #c42275 }
span.s3 { color: #6122ae }
span.s4 { color: #703daa }
span.s5 { color: #0435ff }
span.s6 { color: #3e1e81 }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #000000; background-color: #ffffff }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #3e1e81; background-color: #ffffff }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #000000; background-color: #ffffff; min-height: 20.0px }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #1e9421; background-color: #ffffff }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: #294c50; background-color: #ffffff }
span.s1 { color: #c42275 }
span.s2 { color: #000000 }
span.s3 { color: #1e9421 }
span.s4 { color: #6122ae }
span.s5 { color: #703daa }
span.s6 { color: #0435ff }
span.s7 { color: #3e1e81 }
override func viewDidLoad() {
super.viewDidLoad()
//调用
let mView = UIView(frame: CGRect(origin: CGPoint.zero, size:CGSize(width: 100, height: 100)))
mView.backgroundColor = UIColor.red
self.view.addSubview(mView)
//获取mView的ViewController
let vc = mView.getFirstViewController()
}
原文地址:https://www.cnblogs.com/chenxiaopao/p/9108022.html