No Description

DetailFeatureCell.m 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // DetailFeatureCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/8/25.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "DetailFeatureCell.h"
  9. @interface DetailFeatureCell ()
  10. @property (nonatomic, strong) UIImageView *contentBg;
  11. @end
  12. @implementation DetailFeatureCell
  13. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  14. {
  15. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  16. if (self) {
  17. [self addAllSubviews];
  18. self.selectionStyle = UITableViewCellSelectionStyleNone;
  19. }
  20. return self;
  21. }
  22. - (void)addAllSubviews{
  23. [self.contentView addSubview:self.contentBg];
  24. [self.contentBg mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.edges.insets(UIEdgeInsetsMake(15, 10, 15, 10));
  26. }];
  27. UIView *area0 = [[UIView alloc]init];
  28. UIView *area1 = [[UIView alloc]init];
  29. UIView *area2 = [[UIView alloc]init];
  30. UIView *area3 = [[UIView alloc]init];
  31. [self.contentBg addSubview:area0];
  32. [self.contentBg addSubview:area1];
  33. [self.contentBg addSubview:area2];
  34. [self.contentBg addSubview:area3];
  35. [area0 mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.left.top.equalTo(self.contentBg);
  37. make.right.equalTo(self.contentBg.mas_centerX);
  38. make.bottom.equalTo(self.contentBg.mas_centerY);
  39. }];
  40. [area1 mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.right.top.equalTo(self.contentBg);
  42. make.left.equalTo(self.contentBg.mas_centerX);
  43. make.bottom.equalTo(self.contentBg.mas_centerY);
  44. }];
  45. [area2 mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.bottom.equalTo(self.contentBg);
  47. make.right.equalTo(self.contentBg.mas_centerX);
  48. make.top.equalTo(self.contentBg.mas_centerY);
  49. }];
  50. [area3 mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.right.bottom.equalTo(self.contentBg);
  52. make.left.equalTo(self.contentBg.mas_centerX);
  53. make.top.equalTo(self.contentBg.mas_centerY);
  54. }];
  55. [self configArea:area0 withTitle:@"正品直购" subTitle:@"海外官网直购,更保真" imgName:@"zhengBg" isUp:YES isLeft:YES];
  56. [self configArea:area1 withTitle:@"一键海淘" subTitle:@"一键跟单购买,更省心" imgName:@"taoBg" isUp:YES isLeft:NO];
  57. [self configArea:area2 withTitle:@"实时低价" subTitle:@"同步实时价格,更低价" imgName:@"diBg" isUp:NO isLeft:YES];
  58. [self configArea:area3 withTitle:@"全场包邮" subTitle:@"全场邮费补贴,更任性" imgName:@"baoBg" isUp:NO isLeft:NO];
  59. }
  60. - (void)configArea:(UIView *)area withTitle:(NSString *)title subTitle:(NSString *)subTitle imgName:(NSString *)imgName isUp:(BOOL)isUp isLeft:(BOOL)isLeft{
  61. UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imgName]];
  62. UILabel *titleLabel = ({
  63. UILabel *label = [[UILabel alloc]init];
  64. label.text = title;
  65. label.font = [UIFont systemFontOfSize:13];
  66. label.textColor = UIColorFromRGB(0x333333);
  67. label;
  68. });
  69. UILabel *subTitleLabel = ({
  70. UILabel *label = [[UILabel alloc]init];
  71. label.text = subTitle;
  72. label.font = [UIFont systemFontOfSize:10];
  73. label.textColor = UIColorFromRGB(0x999999);
  74. label;
  75. });
  76. [area addSubview:imageView];
  77. [area addSubview:titleLabel];
  78. [area addSubview:subTitleLabel];
  79. CGFloat iphone6Move = 0;
  80. if (CGRectGetWidth([UIScreen mainScreen].bounds) > 320) iphone6Move = 10;
  81. if (isLeft) { // 在左边
  82. [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.equalTo(area).offset(5 + iphone6Move);
  84. if (isUp) {
  85. make.bottom.equalTo(area).offset(- 7.5);
  86. }else{
  87. make.top.equalTo(area).offset(7.5);
  88. }
  89. }];
  90. [subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.baseline.equalTo(imageView.mas_bottom);
  92. make.left.equalTo(titleLabel);
  93. }];
  94. }else{
  95. CGFloat bottomOff = - 12.5;
  96. if (isUp) bottomOff = - 5.5;
  97. [subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.bottom.equalTo(area).offset(bottomOff);
  99. make.right.equalTo(area).offset(- 5 - iphone6Move);
  100. }];
  101. [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.right.equalTo(subTitleLabel.mas_left).offset(- 10);
  103. make.bottom.equalTo(subTitleLabel.mas_baseline);
  104. }];
  105. }
  106. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.left.equalTo(imageView.mas_right).offset(10);
  108. make.top.equalTo(imageView).offset(3);
  109. }];
  110. }
  111. - (UIImageView *)contentBg{
  112. if (_contentBg == nil) {
  113. UIImage *sizedImg = [[UIImage imageNamed:@"detailLineBg"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10) resizingMode:UIImageResizingModeTile];
  114. _contentBg = [[UIImageView alloc]initWithImage:sizedImg];
  115. }
  116. return _contentBg;
  117. }
  118. @end