SortItemCell.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // SortItemCell.m
  3. // iSales-NPD
  4. //
  5. // Created by Jack on 16/9/5.
  6. // Copyright © 2016年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "SortItemCell.h"
  9. @interface SortItemCell ()
  10. @property (nonatomic,strong) UIButton *selectedView;
  11. @end
  12. @implementation SortItemCell
  13. - (void)awakeFromNib {
  14. [super awakeFromNib];
  15. // Initialization code
  16. }
  17. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  18. [super setSelected:selected animated:animated];
  19. // Configure the view for the selected state
  20. }
  21. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  22. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  23. [self addSubview:self.selectedView];
  24. [self addSubview:self.sortTitleLabel];
  25. self.sortIndex = YES;
  26. }
  27. return self;
  28. }
  29. - (void)setFrame:(CGRect)frame {
  30. [super setFrame:frame];
  31. CGFloat w = CGRectGetWidth(frame);
  32. CGFloat h = CGRectGetHeight(frame);
  33. self.sortTitleLabel.frame = CGRectMake(40, 0, w - 15, h);
  34. self.selectedView.frame = CGRectMake(10, (h - 18) / 2, 18, 18);
  35. }
  36. - (UILabel *)sortTitleLabel {
  37. if (!_sortTitleLabel) {
  38. CGFloat w = CGRectGetWidth(self.bounds);
  39. CGFloat h = CGRectGetHeight(self.bounds);
  40. _sortTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, w - 15, h)];
  41. _sortTitleLabel.backgroundColor = [UIColor clearColor];
  42. _sortTitleLabel.font = [UIFont systemFontOfSize:17];
  43. _sortTitleLabel.textColor = [UIColor blackColor];
  44. _sortTitleLabel.textAlignment = NSTextAlignmentLeft;
  45. }
  46. return _sortTitleLabel;
  47. }
  48. - (UIButton *)selectedView {
  49. if (!_selectedView) {
  50. CGFloat h = CGRectGetHeight(self.bounds);
  51. _selectedView = [[UIButton alloc] initWithFrame:CGRectMake(10, (h - 18) / 2, 18, 18)];
  52. _selectedView.userInteractionEnabled = NO;
  53. }
  54. return _selectedView;
  55. }
  56. - (void)setSortTitle:(NSString *)sortTitle {
  57. _sortTitle = sortTitle;
  58. self.sortTitleLabel.text = sortTitle;
  59. }
  60. - (void)setSelectedSort:(BOOL)selectedSort {
  61. _selectedSort = selectedSort;
  62. self.selectedView.selected = selectedSort;
  63. }
  64. - (void)setSortIndex:(NSInteger)sortIndex {
  65. _sortIndex = sortIndex;
  66. // NSString *selectedImageName = @"";
  67. // switch (sortIndex) {
  68. // case 0:{
  69. // selectedImageName = @"TX_18";
  70. // }
  71. // break;
  72. // case 1:{
  73. // selectedImageName = @"TS_18";
  74. // }
  75. // break;
  76. // case 2:{
  77. // selectedImageName = @"IX_18";
  78. // }
  79. // break;
  80. // case 3:{
  81. // selectedImageName = @"IS_18";
  82. // }
  83. // break;
  84. // case 4:{
  85. // selectedImageName = @"DX_18";
  86. // }
  87. // break;
  88. //
  89. // default:
  90. // break;
  91. // }
  92. // [self.selectedView setImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateSelected];
  93. }
  94. - (void)setSortItem:(NSDictionary *)sortItem {
  95. NSString *title = [sortItem objectForKey:@"title"];
  96. NSString *selectedImageName = [sortItem objectForKey:@"icon"];
  97. self.sortTitle = title;
  98. [self.selectedView setImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateSelected];
  99. }
  100. @end