CLCell.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. 自定义cell。图标大小合适,可控。
  3. 总体和普通cell没区别
  4. */
  5. #import "CLCell.h"
  6. @implementation CLCell
  7. - (void)awakeFromNib {
  8. [super awakeFromNib];
  9. }
  10. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  11. [super setSelected:selected animated:animated];
  12. }
  13. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  14. {
  15. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  16. if (self) {
  17. _headerImg = [[UIImageView alloc] init];
  18. [self.contentView addSubview:_headerImg];
  19. }
  20. return self;
  21. }
  22. +(CLCell*)cellForTableView:(UITableView*)tableView Style:(UITableViewCellStyle)style
  23. {
  24. CLCell* cell = [tableView dequeueReusableCellWithIdentifier:@"CLCell"];
  25. if (!cell) {
  26. cell = [[CLCell alloc] initWithStyle:style reuseIdentifier:@"CLCell"];
  27. }
  28. return cell;
  29. }
  30. +(CGFloat)cellHeight
  31. {
  32. return 40;
  33. }
  34. -(void)layoutSubviews
  35. {
  36. [super layoutSubviews];
  37. CGFloat hei = self.frame.size.height;
  38. CGFloat wid = self.frame.size.width;
  39. CGFloat len = hei*.65;
  40. // CGFloat x,y,w,h;
  41. if (_leftBd < .1) {
  42. _leftBd = 20;
  43. }
  44. self.imageView.frame = CGRectMake( hei - len + 1, (hei - len)/2 + 1, len - 2, len - 2);
  45. if (self.imageView.image) {
  46. self.textLabel.frame = CGRectMake( hei+hei - len, 0, wid- (hei+hei - len)-10, hei);
  47. }else{
  48. self.textLabel.frame = CGRectMake( 0, 0, wid, hei);
  49. }
  50. _headerImg.frame = CGRectMake(wid - hei - 40, 2, hei - 4, hei - 4);
  51. [_headerImg setRound];
  52. }
  53. @end