FLEXTableColumnHeader.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // FLEXTableContentHeaderCell.m
  3. // FLEX
  4. //
  5. // Created by Peng Tao on 15/11/26.
  6. // Copyright © 2015年 f. All rights reserved.
  7. //
  8. #import "FLEXTableColumnHeader.h"
  9. #import "FLEXColor.h"
  10. #import "UIFont+FLEX.h"
  11. #import "FLEXUtility.h"
  12. @interface FLEXTableColumnHeader ()
  13. @property (nonatomic, readonly) UILabel *arrowLabel;
  14. @property (nonatomic, readonly) UIView *lineView;
  15. @end
  16. @implementation FLEXTableColumnHeader
  17. - (instancetype)initWithFrame:(CGRect)frame {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. self.backgroundColor = FLEXColor.secondaryBackgroundColor;
  21. _titleLabel = [UILabel new];
  22. _titleLabel.font = UIFont.flex_defaultTableCellFont;
  23. [self addSubview:_titleLabel];
  24. _arrowLabel = [UILabel new];
  25. _arrowLabel.font = UIFont.flex_defaultTableCellFont;
  26. [self addSubview:_arrowLabel];
  27. _lineView = [UIView new];
  28. _lineView.backgroundColor = FLEXColor.hairlineColor;
  29. [self addSubview:_lineView];
  30. }
  31. return self;
  32. }
  33. - (void)setSortType:(FLEXTableColumnHeaderSortType)type {
  34. _sortType = type;
  35. switch (type) {
  36. case FLEXTableColumnHeaderSortTypeNone:
  37. _arrowLabel.text = @"";
  38. break;
  39. case FLEXTableColumnHeaderSortTypeAsc:
  40. _arrowLabel.text = @"⬆️";
  41. break;
  42. case FLEXTableColumnHeaderSortTypeDesc:
  43. _arrowLabel.text = @"⬇️";
  44. break;
  45. }
  46. }
  47. - (void)layoutSubviews {
  48. [super layoutSubviews];
  49. CGSize size = self.frame.size;
  50. self.titleLabel.frame = CGRectMake(5, 0, size.width - 25, size.height);
  51. self.arrowLabel.frame = CGRectMake(size.width - 20, 0, 20, size.height);
  52. self.lineView.frame = CGRectMake(size.width - 1, 2, FLEXPointsToPixels(1), size.height - 4);
  53. }
  54. @end