NoResultView.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // NoResultView.m
  3. // 乐销
  4. //
  5. // Created by mengxi on 17/1/19.
  6. // Copyright © 2017年 ping. All rights reserved.
  7. //
  8. #import "NoResultView.h"
  9. @implementation NoResultView
  10. #pragma mark 懒加载
  11. - (UILabel *)labelTitle{
  12. if (_labelTitle == nil) {
  13. _labelTitle = [UILabel new];
  14. [GlobalMethod setLabel:_labelTitle widthLimit:0 numLines:0 fontNum:F(14) textColor:COLOR_999 text:@""];
  15. }
  16. return _labelTitle;
  17. }
  18. - (UIView *)lineTop{
  19. if (!_lineTop) {
  20. _lineTop = [UIView new];
  21. _lineTop.frame = CGRectMake(0, 0, SCREEN_WIDTH, 0);
  22. _lineTop.backgroundColor = COLOR_BACKGROUND;
  23. }
  24. return _lineTop;
  25. }
  26. - (UIImageView *)ivNoResult{
  27. if (!_ivNoResult) {
  28. _ivNoResult = [UIImageView new];
  29. _ivNoResult.backgroundColor = [UIColor whiteColor];
  30. }
  31. return _ivNoResult;
  32. }
  33. #pragma mark 初始化
  34. - (instancetype)initWithFrame:(CGRect)frame{
  35. self = [super initWithFrame:frame];
  36. if (self) {
  37. [self addSubView];
  38. }
  39. return self;
  40. }
  41. //添加subview
  42. - (void)addSubView{
  43. self.backgroundColor = [UIColor whiteColor];
  44. [self addSubview:self.labelTitle];
  45. [self addSubview:self.lineTop];
  46. [self addSubview:self.ivNoResult];
  47. }
  48. #pragma mark show
  49. - (void)showInView:(UIView *)viewShow frame:(CGRect)frame{
  50. self.frame = frame;
  51. [self resetView];
  52. [viewShow addSubview:self];
  53. }
  54. #pragma mark 创建
  55. + (instancetype)initWithFrame:(CGRect)frame{
  56. NoResultView * view = [NoResultView new];
  57. view.frame = frame;
  58. [view resetView];
  59. return view;
  60. }
  61. #pragma mark 刷新view
  62. - (void)resetView{
  63. [self removeSubViewWithTag:TAG_LINE];//移除线
  64. //刷新view
  65. self.lineTop.top = 0;
  66. self.lineTop.width = self.width;
  67. self.ivNoResult.image = [UIImage imageNamed:@"nocontain"];
  68. self.ivNoResult.width = W(115);
  69. self.ivNoResult.height = W(91);
  70. self.ivNoResult.centerXTop = XY(self.width / 2, W(55));
  71. [self.labelTitle fitTitle:@"暂无数据" variable:0];
  72. self.labelTitle.centerXTop = XY(self.width / 2,self.ivNoResult.bottom + W(15));
  73. }
  74. //reset with image
  75. - (void)resetWithImageName:(NSString *)imageName{
  76. if (!isStr(imageName)) return;
  77. self.ivNoResult.image = [UIImage imageNamed:imageName];
  78. self.labelTitle.hidden = true;
  79. self.ivNoResult.hidden = false;
  80. }
  81. @end