HolderView.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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:@"community4.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:18]];
  24. [label setTextColor:contentTextColor];
  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. titLabel.height = [_title heightForWid:kSize.width Font:18];
  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 = @"点击刷新";
  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