JXCollectionView.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // JXCollectionView.m
  3. // shiku_im
  4. //
  5. // Created by MacZ on 2016/10/27.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JXCollectionView.h"
  9. @interface JXCollectionView (){
  10. UIImageView *_emptyImg;
  11. UILabel *_tipLabel;
  12. UIButton *_reloadBtn;
  13. }
  14. @end
  15. @implementation JXCollectionView
  16. - (instancetype)initWithFrame:(CGRect)frame
  17. {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. self.alwaysBounceVertical = YES;
  21. }
  22. return self;
  23. }
  24. -(instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout{
  25. self = [super initWithFrame:frame collectionViewLayout:layout];
  26. if (self) {
  27. self.alwaysBounceVertical = YES;
  28. }
  29. return self;
  30. }
  31. - (void)showEmptyImage:(EmptyType)emptyType{
  32. return;
  33. if (!_emptyImg) {
  34. _emptyImg = [[UIImageView alloc]initWithFrame:CGRectMake((JX_SCREEN_WIDTH-56)/2, self.frame.size.height/5, 56, 108)];
  35. _emptyImg.image = [UIImage imageNamed:@"no_data_for_the_time_being"];
  36. [self addSubview:_emptyImg];
  37. // [_emptyImg release];
  38. }
  39. if (!_tipLabel) {
  40. _tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(_emptyImg.frame.origin.x, _emptyImg.frame.origin.y + _emptyImg.frame.size.height + 10, JX_SCREEN_WIDTH, 30)];
  41. CGPoint centerPoint = CGPointMake(_emptyImg.center.x, _emptyImg.frame.origin.y + _emptyImg.frame.size.height + 10);
  42. _tipLabel.center = centerPoint;
  43. _tipLabel.font = g_factory.font16;
  44. _tipLabel.textAlignment = NSTextAlignmentCenter;
  45. [self addSubview:_tipLabel];
  46. // [_tipLabel release];
  47. }
  48. switch (emptyType) {
  49. case EmptyTypeNoData:
  50. _tipLabel.text = Localized(@"JX_NoData");
  51. break;
  52. case EmptyTypeNetWorkError:
  53. _tipLabel.text = Localized(@"JX_NetWorkError");
  54. default:
  55. break;
  56. }
  57. if (!_reloadBtn) {
  58. _reloadBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, _tipLabel.frame.origin.y + _tipLabel.frame.size.height + 20, 120, 40)];
  59. [_reloadBtn setTitle:Localized(@"JX_LoadAgain") forState:UIControlStateNormal];
  60. [_reloadBtn setBackgroundColor:HEXCOLOR(0x48d1cc)];
  61. _reloadBtn.layer.masksToBounds = YES;
  62. _reloadBtn.layer.cornerRadius = 5;
  63. _reloadBtn.center = CGPointMake(JX_SCREEN_WIDTH/2, _reloadBtn.center.y);
  64. [_reloadBtn addTarget:self.delegate
  65. action:@selector(getServerData) forControlEvents:UIControlEventTouchUpInside];
  66. [self addSubview:_reloadBtn];
  67. // [_reloadBtn release];
  68. }
  69. }
  70. - (void)hideEmptyImage{
  71. if (_emptyImg) {
  72. [_emptyImg removeFromSuperview];
  73. _emptyImg = nil;
  74. }
  75. if (_tipLabel) {
  76. [_tipLabel removeFromSuperview];
  77. _tipLabel = nil;
  78. }
  79. if (_reloadBtn) {
  80. [_reloadBtn removeFromSuperview];
  81. _reloadBtn = nil;
  82. }
  83. }
  84. /*
  85. // Only override drawRect: if you perform custom drawing.
  86. // An empty implementation adversely affects performance during animation.
  87. - (void)drawRect:(CGRect)rect {
  88. // Drawing code
  89. }
  90. */
  91. @end