IntroView.m 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // IntroView.m
  3. // model
  4. //
  5. // Created by Drew on 2018/11/1.
  6. // Copyright © 2018年 Mine. All rights reserved.
  7. //
  8. #import "IntroView.h"
  9. @interface IntroView()
  10. @property(nonatomic, strong) Callback confirm;
  11. @property(nonatomic, strong) Callback cancel;
  12. @end
  13. @implementation IntroView
  14. - (instancetype)initWithFrame:(CGRect)frame confirm:(void(^)())confirm cancel:(void(^)())cancel {
  15. if (self = [super initWithFrame:frame]) {
  16. [self initView];
  17. self.confirm = confirm;
  18. self.cancel = cancel;
  19. }
  20. return self;
  21. }
  22. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  23. if (self = [super initWithCoder:aDecoder]) {
  24. [self initView];
  25. }
  26. return self;
  27. }
  28. - (void)initView {
  29. NSBundle *bundle = [NSBundle bundleForClass:[self class]];
  30. NSString *className = NSStringFromClass([self class]);
  31. UIView *view = [[bundle loadNibNamed:className owner:self options:nil] firstObject];
  32. view.frame = self.bounds;
  33. [self addSubview:view];
  34. self.backgroundColor = [UIColor clearColor];
  35. }
  36. - (IBAction)confirm:(id)sender {
  37. [self removeFromSuperview];
  38. if (self.confirm) {
  39. self.confirm();
  40. }
  41. }
  42. - (IBAction)cancel:(id)sender {
  43. [self removeFromSuperview];
  44. if (self.cancel) {
  45. self.cancel();
  46. }
  47. }
  48. @end