HolderView.m 1.7 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. UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  13. iv.center = CGPointMake(frame.size.width/2, frame.size.height/2-40);
  14. [iv setImage:[UIImage imageNamed:@"holder.png"]];
  15. [iv setContentMode:UIViewContentModeScaleAspectFit];
  16. [self addSubview:iv];
  17. y = CGRectGetMaxY(iv.frame);
  18. x = 0;
  19. w = kSize.width;
  20. h = 40 * 2;
  21. UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  22. [label setTextAlignment:NSTextAlignmentCenter];
  23. [label setFont:[UIFont scaleSize:Font18]];
  24. [label setTextColor:KContentTextColor];
  25. [label setNumberOfLines:0];
  26. [self addSubview:label];
  27. titLabel = label;
  28. _title = @"暂无信息~";
  29. }
  30. return self;
  31. }
  32. -(void)layoutSubviews
  33. {
  34. [super layoutSubviews];
  35. [titLabel setText:_title];
  36. }
  37. -(void)freshBlock:(BlockTypeVo)block
  38. {
  39. fresh = block;
  40. if (!btnFul) {
  41. UIButton* btn;
  42. btn = [[UIButton alloc] initWithFrame:self.bounds];
  43. [self addSubview:btn];
  44. btnFul = btn;
  45. _title = [_title stringByAppendingString:@"\n点击刷新"];
  46. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  47. }
  48. }
  49. -(void)btnClick:(UIButton*)sender
  50. {
  51. if (fresh) {
  52. self.hidden = YES;
  53. fresh();
  54. }
  55. }
  56. @end