| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- //
- // SortItemCell.m
- // iSales-NPD
- //
- // Created by Jack on 16/9/5.
- // Copyright © 2016年 United Software Applications, Inc. All rights reserved.
- //
- #import "SortItemCell.h"
- @interface SortItemCell ()
- @property (nonatomic,strong) UIButton *selectedView;
- @end
- @implementation SortItemCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
-
- [self addSubview:self.selectedView];
- [self addSubview:self.sortTitleLabel];
- self.sortIndex = YES;
- }
- return self;
- }
- - (void)setFrame:(CGRect)frame {
- [super setFrame:frame];
- CGFloat w = CGRectGetWidth(frame);
- CGFloat h = CGRectGetHeight(frame);
-
- self.sortTitleLabel.frame = CGRectMake(40, 0, w - 15, h);
- self.selectedView.frame = CGRectMake(10, (h - 18) / 2, 18, 18);
- }
- - (UILabel *)sortTitleLabel {
- if (!_sortTitleLabel) {
- CGFloat w = CGRectGetWidth(self.bounds);
- CGFloat h = CGRectGetHeight(self.bounds);
-
- _sortTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, w - 15, h)];
- _sortTitleLabel.backgroundColor = [UIColor clearColor];
- _sortTitleLabel.font = [UIFont systemFontOfSize:17];
- _sortTitleLabel.textColor = [UIColor blackColor];
- _sortTitleLabel.textAlignment = NSTextAlignmentLeft;
-
- }
- return _sortTitleLabel;
- }
- - (UIButton *)selectedView {
- if (!_selectedView) {
- CGFloat h = CGRectGetHeight(self.bounds);
- _selectedView = [[UIButton alloc] initWithFrame:CGRectMake(10, (h - 18) / 2, 18, 18)];
-
- _selectedView.userInteractionEnabled = NO;
- }
- return _selectedView;
- }
- - (void)setSortTitle:(NSString *)sortTitle {
- _sortTitle = sortTitle;
-
- self.sortTitleLabel.text = sortTitle;
-
- }
- - (void)setSelectedSort:(BOOL)selectedSort {
- _selectedSort = selectedSort;
- self.selectedView.selected = selectedSort;
- }
- - (void)setSortIndex:(NSInteger)sortIndex {
- _sortIndex = sortIndex;
-
- // NSString *selectedImageName = @"";
- // switch (sortIndex) {
- // case 0:{
- // selectedImageName = @"TX_18";
- // }
- // break;
- // case 1:{
- // selectedImageName = @"TS_18";
- // }
- // break;
- // case 2:{
- // selectedImageName = @"IX_18";
- // }
- // break;
- // case 3:{
- // selectedImageName = @"IS_18";
- // }
- // break;
- // case 4:{
- // selectedImageName = @"DX_18";
- // }
- // break;
- //
- // default:
- // break;
- // }
- // [self.selectedView setImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateSelected];
- }
- - (void)setSortItem:(NSDictionary *)sortItem {
- NSString *title = [sortItem objectForKey:@"title"];
- NSString *selectedImageName = [sortItem objectForKey:@"icon"];
- self.sortTitle = title;
- [self.selectedView setImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateSelected];
- }
- @end
|