Swift根据类名加载Xib
2016-07-21 本文已影响49人
Yumazhiyao
import UIKit
class MAXVisitorView: UIView {
class func visitorView() -> MAXVisitorView {
//获取类名
let classFullName = NSStringFromClass(self)
let range = classFullName.rangeOfString(".")?.endIndex
let index = Int(String(range!))!
let className = (classFullName as NSString).substringFromIndex(index)
//返回
return NSBundle.mainBundle().loadNibNamed(className, owner: nil, options: nil).last as! MAXVisitorView
}
}