Swift根据类名加载Xib

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

    }
}

你可能感兴趣的:(Swift根据类名加载Xib)