MoreViewCell.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // MoreViewCell.m
  3. // CGXVerticalMenuView-OC
  4. //
  5. // Created by CGX on 2018/05/01.
  6. // Copyright © 2021 CGX. All rights reserved.
  7. //
  8. #import "MoreViewCell.h"
  9. @interface MoreViewCell()
  10. @property (nonatomic , strong) CGXVerticalMenuMoreListSectionItemModel *model;
  11. @end
  12. @implementation MoreViewCell
  13. - (instancetype)initWithFrame:(CGRect)frame
  14. {
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. [self initializeViews];
  18. }
  19. return self;
  20. }
  21. - (instancetype)initWithCoder:(NSCoder *)coder
  22. {
  23. self = [super initWithCoder:coder];
  24. if (self) {
  25. [self initializeViews];
  26. }
  27. return self;
  28. }
  29. - (void)initializeViews
  30. {
  31. self.layer.masksToBounds = YES;
  32. self.clipsToBounds = YES;
  33. self.urlImageView = [[UIImageView alloc] init];
  34. self.urlImageView.contentMode = UIViewContentModeScaleAspectFit;
  35. [self.contentView addSubview:self.urlImageView];
  36. self.urlImageView.frame = self.bounds;
  37. self.urlImageView.layer.masksToBounds = YES;
  38. self.urlImageView.clipsToBounds = YES;
  39. self.titleLabel =[[UILabel alloc] init];
  40. self.titleLabel.textColor = [UIColor blackColor];
  41. self.titleLabel.font = [UIFont systemFontOfSize:14];
  42. self.titleLabel.numberOfLines = 0;
  43. self.titleLabel.textAlignment = NSTextAlignmentLeft;
  44. [self.contentView addSubview:self.titleLabel];
  45. }
  46. - (void)layoutSubviews
  47. {
  48. [super layoutSubviews];
  49. }
  50. - (void)reloadData:(CGXVerticalMenuMoreListSectionItemModel *)model
  51. {
  52. self.model = model;
  53. self.urlImageView.frame = CGRectMake(10, 10, CGRectGetHeight(self.contentView.frame)-20, CGRectGetHeight(self.contentView.frame)-20);
  54. self.titleLabel.frame = CGRectMake(CGRectGetMaxX(self.urlImageView.frame)+20, 0, CGRectGetWidth(self.contentView.frame)-CGRectGetMaxX(self.urlImageView.frame)-30, CGRectGetHeight(self.contentView.frame));
  55. self.contentView.backgroundColor = model.itemBgColor;
  56. self.urlImageView.layer.cornerRadius = model.itemCornerRadius;
  57. self.contentView.layer.borderWidth = model.itemBborderWidth;
  58. self.contentView.layer.borderColor = [model.itemBorderColor CGColor];
  59. self.contentView.layer.cornerRadius = model.itemCornerRadius;
  60. __weak typeof(self) weakSelf = self;
  61. if ([model.itemUrlStr hasPrefix:@"http:"] || [model.itemUrlStr hasPrefix:@"https:"]) {
  62. if (model.menu_ImageCallback) {
  63. model.menu_ImageCallback(weakSelf.urlImageView, [NSURL URLWithString:model.itemUrlStr]);
  64. }
  65. } else{
  66. UIImage *image = [UIImage imageNamed:model.itemUrlStr];
  67. if (!image) {
  68. image = [UIImage imageWithContentsOfFile:model.itemUrlStr];
  69. }
  70. self.urlImageView.image = image;
  71. }
  72. self.titleLabel.text = model.itemText;
  73. self.titleLabel.textColor = model.itemColor;
  74. self.titleLabel.font = model.itemFont;
  75. self.titleLabel.numberOfLines = model.numberOfLines;
  76. }
  77. @end