123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //
- // XYVoiceMatchOrderDetailsInfoView.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/11/20.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYVoiceMatchOrderDetailsInfoView.h"
- #import "XYVoiceChatDetailsModel.h"
- @interface XYVoiceMatchOrderDetailsInfoView ()
- @property (nonatomic, strong) UIView *detailsInfoView;
- @property (nonatomic, strong) UIView *amountView;
- @property (nonatomic, strong) UIView *amountLine;
- @property (nonatomic, strong) UILabel *amountTitleLabel;
- @property (nonatomic, strong) UILabel *amountLabel;
- @end
- @implementation XYVoiceMatchOrderDetailsInfoView
- #pragma mark — Public
- - (void)setupViewDataWithModel:(XYVoiceChatDetailsModel *)model {
- [self buildDetailsInfoViewWithModel:model];
-
- self.amountLabel.text = StringIsEmpty(model.consumeAmount)?@"- -":[NSString stringWithFormat:@"%@%@", model.consumeAmount, App_CoinName(Wallet_Type_Star_Diamond)];
- }
- - (void)buildDetailsInfoViewWithModel:(XYVoiceChatDetailsModel *)model {
-
- NSArray *infos = @[kLocalizedString(@"订单编号:"), [NSString stringWithFormat:@"%@ %@", model.hisId, kLocalizedString(@"复制")], kLocalizedString(@"品类:"), model.skillName, kLocalizedString(@"单价:"), [NSString stringWithFormat:@"%@%@/%@", model.hisPrice, App_CoinName(Wallet_Type_Star_Diamond), model.unitText], kLocalizedString(@"数量:"), @"1"];
- for (UIView *view in self.detailsInfoView.subviews) {
- [view removeFromSuperview];
- }
-
- UILabel *tempLabel;
- for (NSInteger i = 0; i < infos.count; i++) {
- UILabel *label = [UILabel new];
- label.font = Font(14);
- label.text = infos[i];
- [self.detailsInfoView addSubview:label];
- if (i%2 == 0) {
- // 奇数
- [label mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.detailsInfoView).offset(20.0f);
- if (tempLabel) {
- make.top.equalTo(tempLabel.mas_bottom).offset(10.0f);
- }else {
- make.top.equalTo(self.detailsInfoView).offset(21.0f);
- }
- make.width.equalTo(@70.0f);
- make.height.equalTo(@(20.0f));
- }];
- }else {
- // 偶数
- label.textColor = Color_TextFont;
- label.textAlignment = NSTextAlignmentRight;
- [label mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(tempLabel.mas_right).offset(20.0f);
- make.right.equalTo(self.detailsInfoView).offset(-20.0f);
- make.top.equalTo(tempLabel);
- make.height.equalTo(@(20.0f));
- }];
- }
- if (i == 1) {
- // 修改颜色
- [HandleString changeLabelColor:label string:kLocalizedString(@"复制") textColor:Color_Blue];
-
- // 添加复制事件
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyAction:)];
- label.userInteractionEnabled = YES;
- [label addGestureRecognizer:tap];
- [label sizeToFit];
- }
- tempLabel = label;
- }
- }
- - (void)copyAction:(UITapGestureRecognizer *)tap {
- UILabel *label = (UILabel *)tap.view;
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.string = [NSString stringWithFormat:@"%@", [label.text substringToIndex:label.text.length - 2]];
- [SVProgressHUD showSuccessWithStatus:kLocalizedString(@"已复制至剪切板")];
- }
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI {
- [self addSubview:self.detailsInfoView];
- [self addSubview:self.amountView];
- [self.amountView addSubview:self.amountLine];
- [self.amountView addSubview:self.amountTitleLabel];
- [self.amountView addSubview:self.amountLabel];
-
- [self.detailsInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.equalTo(self);
- make.height.equalTo(@152.0f);
- }];
- [self.amountView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self);
- make.height.equalTo(@54.0f);
- }];
- [self.amountLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.equalTo(self.amountView);
- make.height.equalTo(@(LINE_HEIGHT));
- }];
- [self.amountTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.amountView).offset(20.0f);
- make.centerY.equalTo(self.amountView);
- }];
- [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.amountView).offset(-20.0f);
- make.centerY.equalTo(self.amountView);
- }];
- }
- #pragma mark — Getter
- - (UIView *)detailsInfoView {
- if (!_detailsInfoView) {
- _detailsInfoView = [UIView new];
- _detailsInfoView.backgroundColor = Color_Clear;
- }
- return _detailsInfoView;
- }
- - (UIView *)amountView {
- if (!_amountView) {
- _amountView = [UIView new];
- }
- return _amountView;
- }
- - (UIView *)amountLine {
- if (!_amountLine) {
- _amountLine = [UIView new];
- _amountLine.backgroundColor = Color_line;
- }
- return _amountLine;
- }
- - (UILabel *)amountTitleLabel {
- if (!_amountTitleLabel) {
- _amountTitleLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_S(15)];
- _amountTitleLabel.text = kLocalizedString(@"合计:");
- }
- return _amountTitleLabel;
- }
- - (UILabel *)amountLabel {
- if (!_amountLabel) {
- _amountLabel = [UILabel createLabelTextColor:Color_TextRed fount:Font_S(15)];
- _amountLabel.textAlignment = NSTextAlignmentRight;
- }
- return _amountLabel;
- }
- @end
|