Files
peko-ios/YuMi/CustomUI/MoliMoneyLabel.m
2025-04-02 11:04:07 +08:00

91 lines
2.7 KiB
Objective-C

//
// MoliMoneyLabel.m
// YuMi
//
// Created by P on 2025/2/25.
//
#import "MoliMoneyLabel.h"
@interface MoliMoneyLabel()
@property(nonatomic, strong) UILabel *label;
@property(nonatomic, strong) UIImageView *money;
@property(nonatomic, strong) UIView *spaceView;
@property(nonatomic, strong) UIStackView *stackView;
@end
@implementation MoliMoneyLabel
+ (MoliMoneyLabel *)moneyLabelWithTextColot:(UIColor *)textColor
font:(UIFont *)font
moneyPostion:(NSInteger)position
moneySize:(CGSize)size {
MoliMoneyLabel *containerView = [[MoliMoneyLabel alloc] init];
containerView.label = [UILabel labelInitWithText:@"" font:font textColor:textColor];
containerView.label.minimumScaleFactor = 0.7;
containerView.label.adjustsFontSizeToFitWidth = YES;
containerView.money = [[UIImageView alloc] initWithImage:kImage(@"moli_money_icon")];
containerView.money.contentMode = UIViewContentModeScaleAspectFill;
containerView.spaceView = [[UIView alloc] init];
NSArray *subviews = position == 1 ? @[containerView.spaceView, containerView.money, containerView.label] : @[containerView.spaceView, containerView.label, containerView.money];
containerView.stackView = [[UIStackView alloc] initWithArrangedSubviews:subviews];
containerView.stackView.spacing = 3;
containerView.stackView.distribution = UIStackViewDistributionFillProportionally;
containerView.stackView.alignment = UIStackViewAlignmentCenter;
[containerView addSubview:containerView.stackView];
[containerView.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(containerView);
}];
[containerView.money mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(size);
}];
return containerView;
}
- (void)hideAll {
self.spaceView.hidden = YES;
self.stackView.hidden = YES;
self.money.hidden = YES;
}
- (void)removeSpace {
[self.stackView removeArrangedSubview:self.spaceView];
}
- (void)updateSpacing:(NSInteger)space {
self.stackView.spacing = space;
}
- (void)displayIcon:(BOOL)displayOrNot {
self.money.hidden = !displayOrNot;
}
- (void)updateContent:(NSString *)content {
self.label.text = content;
}
- (void)updateFont:(UIFont *)font size:(CGSize)size {
self.label.font = font;
[self.money mas_updateConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(size);
}];
}
- (void)updateLabelAlignment:(NSTextAlignment)alignment {
self.label.textAlignment = alignment;
}
- (void)insertSpaceAtLeast {
UIView *space = [[UIView alloc] init];
[self.stackView addArrangedSubview:space];
}
@end