//
//  UIView+loadFromNib : xibからUIView(の派生クラス)を読み込む
//
//  Created by EIMEI on 2013/02/11.
//  Copyright (c) 2013年 stack3. All rights reserved.
//	http://blogios.stack3.net/archives/195
//

#import "UIView+loadFromNib.h"

@implementation UIView (loadFromNib)

/// @brief xibからUIView(の派生クラス)を読み込む
/// @discussion 読み込むファイル名はクラス名.xib
+ (id)loadFromNib
{
    NSString *nibName = NSStringFromClass([self class]);
	nslog(@"loadFromNib:%@",nibName);
    UINib *nib = [UINib nibWithNibName:nibName bundle:nil];
    return [nib instantiateWithOwner:nil options:nil][0];
}

/// @brief xibから、iPhone/iPadそれぞれに対応したUIView(の派生クラス)を読み込む
/// @discussion 読み込むファイル名はクラス名_iPhone.xibまたはクラス名_iPad.xib
+ (id)loadFromIdiomNib
{
    NSString *nibName = NSStringFromClass([self class]);
	nslog(@"loadFromIdiomNib:%@",nibName);
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        nibName = [nibName stringByAppendingString:@"_iPhone"];
    } else {
        nibName = [nibName stringByAppendingString:@"_iPad"];
    }
    UINib *nib = [UINib nibWithNibName:nibName bundle:nil];
    return [nib instantiateWithOwner:nil options:nil][0];
}

@end
