123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //
- // XYVoiceMatchButton.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/12/4.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYVoiceMatchButton.h"
- @interface XYVoiceMatchButton ()
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UILabel *subtitleLabel;
- @property (nonatomic, strong) UIButton *actionButton;
- @end
- @implementation XYVoiceMatchButton
- - (void)setTitle:(NSString *)title {
- _title = title;
- self.titleLabel.text = title;
- }
- - (void)setSubtitle:(NSString *)subtitle {
- _subtitle = subtitle;
- self.subtitleLabel.text = subtitle;
- if (StringIsEmpty(subtitle)) {
- // 只有一个标题
- [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(10.0f);
- }];
- }else {
- // 两个标题
- [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(3.0f);
- }];
- }
- }
- #pragma mark — Action
- - (void)actionButtonAction:(id)sender {
- if (self.actionButtonBlock) {
- self.actionButtonBlock();
- }
- }
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI {
-
- [self addSubview:self.titleLabel];
- [self addSubview:self.subtitleLabel];
- [self addSubview:self.actionButton];
-
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self).offset(10.0f);
- make.right.equalTo(self).offset(-10.0f);
- make.top.equalTo(self).offset(3.0f);
- make.height.equalTo(@20.0f);
- }];
- [self.subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self).offset(10.0f);
- make.right.equalTo(self).offset(-10.0f);
- make.top.equalTo(self.titleLabel.mas_bottom);
- make.height.equalTo(@14.0f);
- }];
- [self.actionButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
- }
- #pragma mark — Getter
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [UILabel createLabelTextColor:Color_White fount:Font_B(14)];
- _titleLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _titleLabel;
- }
- - (UILabel *)subtitleLabel {
- if (!_subtitleLabel) {
- _subtitleLabel = [UILabel createLabelTextColor:Color_White fount:Font(10)];
- _subtitleLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _subtitleLabel;
- }
- - (UIButton *)actionButton {
- if (!_actionButton) {
- _actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _actionButton.backgroundColor = Color_Clear;
- [_actionButton addTarget:self action:@selector(actionButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _actionButton;
- }
- @end
|