123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- //
- // DRBottomRuleView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/11/21.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DRBottomRuleView.h"
- #import "DRMiddlePrvilegeModel.h"
- @interface DRBottomRuleView ()
- @property (nonatomic, strong) UIView *leftLine;
- @property (nonatomic, strong) UIView *rightLine;
- @property (nonatomic, strong) UILabel *titleLb;
- @end
- @implementation DRBottomRuleView
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self initUI];
- [self loadData];
- }
- return self;
- }
- - (void)initUI {
-
- [self addSubview:self.titleLb];
- [self addSubview:self.leftLine];
- [self addSubview:self.rightLine];
-
- [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.mas_centerX);
- make.top.mas_equalTo(12);
- }];
-
-
- [self.leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(self.titleLb.mas_left).mas_offset(-10);
- make.centerY.mas_equalTo(self.titleLb.mas_centerY);
- make.height.mas_equalTo(2);
- make.width.mas_equalTo(40);
- }];
-
-
- [self.rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.titleLb.mas_right).mas_offset(10);
- make.centerY.mas_equalTo(self.titleLb.mas_centerY);
- make.height.mas_equalTo(2);
- make.width.mas_equalTo(40);
- }];
- }
- - (void)loadData {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/getPrivilege",BaseURL];
- [DRHttp post:url params:nil success:^(id json) {
- NSArray *list = [NSArray yy_modelArrayWithClass:[DRMiddlePrvilegeModel class] json:json[@"data"][@"role"]];
-
- [self configSubRules:list];
-
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)configSubRules:(NSArray *)list {
-
- UILabel *lastLabel = self.titleLb;
- for (int i = 0; i < list.count; i++) {
- DRMiddlePrvilegeModel *model = list[i];
- UILabel *label = [[UILabel alloc] init];
- label.numberOfLines = 0;
- label.textColor = [UIColor YHColorWithHex:0x666666];
- NSString *text = [NSString stringWithFormat:@"%@%@",model.title,model.content];
-
-
- NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text];
- NSRange range = [text rangeOfString:model.title];
- [attr addAttribute:NSForegroundColorAttributeName value:[UIColor YHColorWithHex:0x333333] range:range];
-
- //行间距
- NSMutableParagraphStyle * mParagraphStyle = [[NSMutableParagraphStyle alloc] init];
- mParagraphStyle.lineSpacing = 5;
- [attr addAttribute:NSParagraphStyleAttributeName value:mParagraphStyle range:range];
-
- label.attributedText = attr;
-
- label.font = [UIFont systemFontOfSize:13];
- [self addSubview:label];
-
- [label mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(15);
- make.right.mas_equalTo(-15);
- make.top.mas_equalTo(lastLabel.mas_bottom).mas_offset(7);
- }];
-
- lastLabel = label;
- }
-
- [self mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(lastLabel.mas_bottom).mas_offset(10);
- }];
- if (self.layoutComplete) {
- self.layoutComplete();
- }
- [self layoutIfNeeded];
-
- }
- - (UIView *)leftLine {
- if (!_leftLine) {
- _leftLine = [[UIView alloc] init];
- _leftLine.backgroundColor = [UIColor YHColorWithHex:0x333333];
- }
- return _leftLine;
- }
- - (UIView *)rightLine {
- if (!_rightLine) {
- _rightLine = [[UIView alloc] init];
- _rightLine.backgroundColor = [UIColor YHColorWithHex:0x333333];
- }
- return _rightLine;
- }
- - (UILabel *)titleLb {
- if (!_titleLb) {
- _titleLb = [[UILabel alloc] init];
- _titleLb.font = [UIFont systemFontOfSize:15];
- _titleLb.textColor = [UIColor YHColorWithHex:0x333333];
- _titleLb.textAlignment = NSTextAlignmentCenter;
- _titleLb.text = @"升级规则";
- }
- return _titleLb;
- }
- @end
|