| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- //
- // BaseTableViewCell.m
- // zhuxun
- //
- // Created by winsoft on 16/8/24.
- //
- //
- #import "BaseTableViewCell.h"
- #define MarginX 20
- #define BtnWH 20
- @interface BaseTableViewCell()
- @property (nonatomic , weak, readonly) UIImageView *selectView;
- @end
- @implementation BaseTableViewCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
-
- UIImageView *selectView = [[UIImageView alloc]init];
- [self addSubview:selectView];
- _selectView = selectView;;
-
- }
-
- return self;
- }
- - (void)setIndexPath:(NSIndexPath *)indexPath
- {
- _indexPath = indexPath;
-
- [self setNeedsDisplay];
- }
- - (void)drawRect:(CGRect)rect
- {
- [super drawRect:rect];
-
- long maxRowIndex = [self.tableView numberOfRowsInSection:_indexPath.section];
-
- //可能maxrowindex = 0的情况
-
- UIBezierPath *path = [[UIBezierPath alloc] init];
-
- //第一行
- if (self.indexPath.row == 0) {
- [path moveToPoint:CGPointMake(0, 0)];
- [path addLineToPoint:CGPointMake(self.frame.size.width, 0)];
-
- //下部分
- }else if (self.indexPath.row != 0)
- {
- [path moveToPoint:CGPointMake(MarginX, 0)];
- [path addLineToPoint:CGPointMake(self.frame.size.width, 0)];
-
-
- }
-
-
- //最后一行,需要画两行..上下.
- if (_indexPath.row == maxRowIndex - 1)
- {
- [path moveToPoint:CGPointMake(0, self.frame.size.height)];
- [path addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height)];
- }
-
-
-
- [path setLineWidth:0.5];
-
- [LineForDrawColor set];
-
- [path stroke];
- }
- - (void)setFrame:(CGRect)frame
- {
- CGRect orgFrame = frame;
- orgFrame.origin.y += self.insertY;
- orgFrame.size.height -= self.insertY;
- [super setFrame:orgFrame];
- }
- - (void)setCellSelected:(BOOL)isSelected
- {
- _cellSelected = isSelected;
-
- if (isSelected) {
- [self.selectView setImage:[UIImage imageNamed:@"file_selected"]];
- }else [self.selectView setImage:[UIImage imageNamed:@"file_unselected"]];
- }
- - (void)setAllowsMultipleSelection:(BOOL)allowsMultipleSelection
- {
- _allowsMultipleSelection = allowsMultipleSelection;
-
- [self setNeedsLayout];
-
- if (self.allowsMultipleSelection) {
- self.selectView.hidden = NO;
-
- }else {
- self.selectView.hidden = YES;
- }
- }
- - (void)layoutSubviews
- {
- [super layoutSubviews];
-
- if (self.allowsMultipleSelection) {
- self.selectView.frame = CGRectMake(5, self.frame.size.height/2.0f - BtnWH/2.0f, BtnWH, BtnWH);
-
- CGRect contentViewFram = self.contentView.frame;
- contentViewFram.origin.x += CGRectGetMaxX(self.selectView.frame);
- self.contentView.frame = contentViewFram;
-
- }else {
- self.selectView.frame = CGRectZero;
-
- CGRect contentViewFram = self.contentView.frame;
- contentViewFram.origin.x = 0;
- self.contentView.frame = contentViewFram;
-
-
- }
-
-
- }
- @end
|