HolderView.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #import "HolderView.h"
  2. @implementation HolderView
  3. - (instancetype)initWithFrame:(CGRect)frame
  4. {
  5. self = [super initWithFrame:frame];
  6. if (self) {
  7. [self setBackgroundColor:[UIColor whiteColor]];
  8. self.clipsToBounds = YES;
  9. CGFloat x,y,w,h;
  10. w = h = kSize.width/3.0;
  11. x = y = w;
  12. y +=64;
  13. UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  14. iv.center = CGPointMake(frame.size.width/2, frame.size.height/2-50/2);
  15. [iv setImage:[UIImage imageNamed:@"holder.png"]];
  16. [iv setContentMode:UIViewContentModeScaleAspectFit];
  17. [self addSubview:iv];
  18. y = CGRectGetMaxY(iv.frame);
  19. x = 0;
  20. w = kSize.width;
  21. h = 50;
  22. UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  23. [label setTextAlignment:NSTextAlignmentCenter];
  24. [label setTextColor:[UIColor darkGrayColor]];
  25. [label setFont:[UIFont systemFontOfSize:18]];
  26. [label setNumberOfLines:0];
  27. [self addSubview:label];
  28. titLabel = label;
  29. _title = @"暂无信息~";
  30. }
  31. return self;
  32. }
  33. -(void)layoutSubviews
  34. {
  35. [super layoutSubviews];
  36. [titLabel setText:_title];
  37. }
  38. -(void)freshBlock:(BlockTypeVo)block
  39. {
  40. fresh = block;
  41. if (!btnFul) {
  42. UIButton* btn;
  43. btn = [[UIButton alloc] initWithFrame:self.bounds];
  44. [self addSubview:btn];
  45. btnFul = btn;
  46. _title = [_title stringByAppendingString:@"\n点击刷新"];
  47. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  48. }
  49. }
  50. -(void)btnClick:(UIButton*)sender
  51. {
  52. if (fresh) {
  53. self.hidden = YES;
  54. fresh();
  55. }
  56. }
  57. @end