悟空记账

UIView+Nib.m 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // UIView+Nib.m
  3. // DHBaseProject_ZJ
  4. //
  5. // Created by 我的大好时光 on 2017/4/1.
  6. // Copyright © 2017年 dhyt. All rights reserved.
  7. //
  8. #import "UIView+Nib.h"
  9. @implementation UIView (Nib)
  10. #pragma mark - Nibs
  11. + (UINib *)dh_loadNib
  12. {
  13. return [self dh_loadNibNamed:NSStringFromClass([self class])];
  14. }
  15. + (UINib *)dh_loadNibNamed:(NSString*)nibName
  16. {
  17. return [self dh_loadNibNamed:nibName bundle:[NSBundle mainBundle]];
  18. }
  19. + (UINib *)dh_loadNibNamed:(NSString*)nibName bundle:(NSBundle *)bundle
  20. {
  21. return [UINib nibWithNibName:nibName bundle:bundle];
  22. }
  23. + (instancetype)dh_loadInstanceFromNib
  24. {
  25. return [self dh_loadInstanceFromNibWithName:NSStringFromClass([self class])];
  26. }
  27. + (instancetype)dh_loadInstanceFromNibWithName:(NSString *)nibName
  28. {
  29. return [self dh_loadInstanceFromNibWithName:nibName owner:nil];
  30. }
  31. + (instancetype)dh_loadInstanceFromNibWithName:(NSString *)nibName owner:(id)owner
  32. {
  33. return [self dh_loadInstanceFromNibWithName:nibName owner:owner bundle:[NSBundle mainBundle]];
  34. }
  35. + (instancetype)dh_loadInstanceFromNibWithName:(NSString *)nibName owner:(id)owner bundle:(NSBundle *)bundle
  36. {
  37. UIView *result = nil;
  38. NSArray* elements = [bundle loadNibNamed:nibName owner:owner options:nil];
  39. for (id object in elements)
  40. {
  41. if ([object isKindOfClass:[self class]])
  42. {
  43. result = object;
  44. break;
  45. }
  46. }
  47. return result;
  48. }
  49. @end