《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRBottomRuleView.m 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // DRBottomRuleView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/11/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRBottomRuleView.h"
  9. #import "DRMiddlePrvilegeModel.h"
  10. @interface DRBottomRuleView ()
  11. @property (nonatomic, strong) UIView *leftLine;
  12. @property (nonatomic, strong) UIView *rightLine;
  13. @property (nonatomic, strong) UILabel *titleLb;
  14. @end
  15. @implementation DRBottomRuleView
  16. - (instancetype)initWithFrame:(CGRect)frame
  17. {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. [self initUI];
  21. [self loadData];
  22. }
  23. return self;
  24. }
  25. - (void)initUI {
  26. [self addSubview:self.titleLb];
  27. [self addSubview:self.leftLine];
  28. [self addSubview:self.rightLine];
  29. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.centerX.mas_equalTo(self.mas_centerX);
  31. make.top.mas_equalTo(12);
  32. }];
  33. [self.leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.right.mas_equalTo(self.titleLb.mas_left).mas_offset(-10);
  35. make.centerY.mas_equalTo(self.titleLb.mas_centerY);
  36. make.height.mas_equalTo(2);
  37. make.width.mas_equalTo(40);
  38. }];
  39. [self.rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.mas_equalTo(self.titleLb.mas_right).mas_offset(10);
  41. make.centerY.mas_equalTo(self.titleLb.mas_centerY);
  42. make.height.mas_equalTo(2);
  43. make.width.mas_equalTo(40);
  44. }];
  45. }
  46. - (void)loadData {
  47. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/getPrivilege",BaseURL];
  48. [DRHttp post:url params:nil success:^(id json) {
  49. NSArray *list = [NSArray yy_modelArrayWithClass:[DRMiddlePrvilegeModel class] json:json[@"data"][@"role"]];
  50. [self configSubRules:list];
  51. } failure:^(NSError *error) {
  52. }];
  53. }
  54. - (void)configSubRules:(NSArray *)list {
  55. UILabel *lastLabel = self.titleLb;
  56. for (int i = 0; i < list.count; i++) {
  57. DRMiddlePrvilegeModel *model = list[i];
  58. UILabel *label = [[UILabel alloc] init];
  59. label.numberOfLines = 0;
  60. label.textColor = [UIColor YHColorWithHex:0x666666];
  61. NSString *text = [NSString stringWithFormat:@"%@%@",model.title,model.content];
  62. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text];
  63. NSRange range = [text rangeOfString:model.title];
  64. [attr addAttribute:NSForegroundColorAttributeName value:[UIColor YHColorWithHex:0x333333] range:range];
  65. //行间距
  66. NSMutableParagraphStyle * mParagraphStyle = [[NSMutableParagraphStyle alloc] init];
  67. mParagraphStyle.lineSpacing = 5;
  68. [attr addAttribute:NSParagraphStyleAttributeName value:mParagraphStyle range:range];
  69. label.attributedText = attr;
  70. label.font = [UIFont systemFontOfSize:13];
  71. [self addSubview:label];
  72. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.mas_equalTo(15);
  74. make.right.mas_equalTo(-15);
  75. make.top.mas_equalTo(lastLabel.mas_bottom).mas_offset(7);
  76. }];
  77. lastLabel = label;
  78. }
  79. [self mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.bottom.mas_equalTo(lastLabel.mas_bottom).mas_offset(10);
  81. }];
  82. if (self.layoutComplete) {
  83. self.layoutComplete();
  84. }
  85. [self layoutIfNeeded];
  86. }
  87. - (UIView *)leftLine {
  88. if (!_leftLine) {
  89. _leftLine = [[UIView alloc] init];
  90. _leftLine.backgroundColor = [UIColor YHColorWithHex:0x333333];
  91. }
  92. return _leftLine;
  93. }
  94. - (UIView *)rightLine {
  95. if (!_rightLine) {
  96. _rightLine = [[UIView alloc] init];
  97. _rightLine.backgroundColor = [UIColor YHColorWithHex:0x333333];
  98. }
  99. return _rightLine;
  100. }
  101. - (UILabel *)titleLb {
  102. if (!_titleLb) {
  103. _titleLb = [[UILabel alloc] init];
  104. _titleLb.font = [UIFont systemFontOfSize:15];
  105. _titleLb.textColor = [UIColor YHColorWithHex:0x333333];
  106. _titleLb.textAlignment = NSTextAlignmentCenter;
  107. _titleLb.text = @"升级规则";
  108. }
  109. return _titleLb;
  110. }
  111. @end