标签:ati ber ring omv gauss font swift iter xib
1.oc版
+ (instancetype)viewFromXib {
NSBundle* bundle = [NSBundle mainBundle];
NSString* className = NSStringFromClass([self class]);
return [[bundle loadNibNamed:className owner:nil options:nil] objectAtIndexSafe:0];
}
使用:
CustomView* view = [CustomView viewFromXib];
2.swift版
static func newInstance() -> LeftView? {
let objc = Bundle.main.loadNibNamed("LeftView", owner: nil, options: nil)
if let view = objc?.first as? LeftView {
return view
}
return nil
}
使用:
let view = CustomView.
newInstance()!
标签:ati ber ring omv gauss font swift iter xib
原文地址:http://www.cnblogs.com/weicyNo-1/p/7509052.html