// // KBGuideTopCell.m // keyBoard // #import "KBGuideTopCell.h" @interface KBGuideTopCell () // 左侧头像(使用 App_icon 素材) @property (nonatomic, strong) UIImageView *avatarImageView; // 白色卡片容器 @property (nonatomic, strong) UIView *cardView; // 卡片标题/正文 @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UILabel *descLabel; @property (nonatomic, strong) UIStackView *buttonStack; @property (nonatomic, strong) UIButton *q1Button; @property (nonatomic, strong) UIButton *q2Button; @end @implementation KBGuideTopCell - (void)setupUI { self.backgroundColor = [UIColor clearColor]; self.contentView.backgroundColor = [UIColor clearColor]; // 头像 [self.contentView addSubview:self.avatarImageView]; [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(16); make.top.equalTo(self.contentView).offset(12); make.width.height.mas_equalTo(36); }]; // 卡片 [self.contentView addSubview:self.cardView]; [self.cardView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.avatarImageView.mas_right).offset(8); make.right.lessThanOrEqualTo(self.contentView).offset(-32); make.top.equalTo(self.contentView).offset(8); make.bottom.equalTo(self.contentView).offset(-8); }]; [self.cardView addSubview:self.titleLabel]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.equalTo(self.cardView).offset(12); make.right.equalTo(self.cardView).offset(-12); }]; [self.cardView addSubview:self.descLabel]; [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.titleLabel.mas_bottom).offset(6); make.left.right.equalTo(self.titleLabel); }]; // 示例按钮区域 [self.cardView addSubview:self.buttonStack]; [self.buttonStack mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.descLabel.mas_bottom).offset(20); make.left.equalTo(self.cardView).offset(12); make.right.equalTo(self.cardView).offset(-12); make.bottom.equalTo(self.cardView).offset(-16); }]; [self.buttonStack addArrangedSubview:self.q1Button]; [self.buttonStack addArrangedSubview:self.q2Button]; [self.q1Button mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(46); }]; [self.q2Button mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(46); }]; } #pragma mark - Lazy - (UIImageView *)avatarImageView { if (!_avatarImageView) { _avatarImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"App_icon"]]; _avatarImageView.contentMode = UIViewContentModeScaleAspectFill; _avatarImageView.layer.cornerRadius = 18; _avatarImageView.layer.masksToBounds = YES; } return _avatarImageView; } - (UIView *)cardView { if (!_cardView) { _cardView = [UIView new]; _cardView.backgroundColor = [UIColor whiteColor]; _cardView.layer.cornerRadius = 20; _cardView.layer.masksToBounds = NO; _cardView.layer.shadowColor = [UIColor colorWithRed:0.42 green:0.54 blue:0.83 alpha:0.35].CGColor; _cardView.layer.shadowOpacity = 0.5; _cardView.layer.shadowOffset = CGSizeMake(0, 6); _cardView.layer.shadowRadius = 14; } return _cardView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [UILabel new]; _titleLabel.numberOfLines = 0; _titleLabel.font = [KBFont regular:10]; _titleLabel.textColor = [UIColor colorWithHex:0x929292]; _titleLabel.text = KBLocalized(@"Welcome To Use The [key Of Love] Keyboard"); } return _titleLabel; } - (UILabel *)descLabel { if (!_descLabel) { _descLabel = [UILabel new]; _descLabel.numberOfLines = 0; _descLabel.font = [KBFont regular:10]; _descLabel.textColor = [UIColor colorWithHex:0x929292]; NSString *desc = KBLocalized(@"Click \"copy Any Conversation\", \"paste\"\nAnd Try Replying Using The Keyboard\n[persona] Method"); NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; style.lineSpacing = 4; _descLabel.attributedText = [[NSAttributedString alloc] initWithString:desc attributes:@{ NSParagraphStyleAttributeName : style }]; } return _descLabel; } - (UIStackView *)buttonStack { if (!_buttonStack) { _buttonStack = [[UIStackView alloc] init]; _buttonStack.axis = UILayoutConstraintAxisVertical; _buttonStack.distribution = UIStackViewDistributionFill; _buttonStack.spacing = 10; } return _buttonStack; } - (UIButton *)q1Button { if (!_q1Button) { _q1Button = [self kb_makeActionButton]; [_q1Button setTitle:KBLocalized(@"I Miss You") forState:UIControlStateNormal]; [_q1Button addTarget:self action:@selector(kb_onTapQ1) forControlEvents:UIControlEventTouchUpInside]; } return _q1Button; } - (UIButton *)q2Button { if (!_q2Button) { _q2Button = [self kb_makeActionButton]; [_q2Button setTitle:KBLocalized(@"I'm Going To Take A Bath") forState:UIControlStateNormal]; [_q2Button addTarget:self action:@selector(kb_onTapQ2) forControlEvents:UIControlEventTouchUpInside]; } return _q2Button; } - (UIButton *)kb_makeActionButton { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.backgroundColor = [UIColor whiteColor]; btn.layer.cornerRadius = 4; btn.backgroundColor = [UIColor colorWithHex:0xF3F3F3]; // btn.layer.borderWidth = 1; // btn.layer.borderColor = [UIColor colorWithRed:0.82 green:0.86 blue:0.99 alpha:1].CGColor; btn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold]; [btn setTitleColor:[UIColor colorWithHex:0x1B1F1A] forState:UIControlStateNormal]; btn.titleLabel.numberOfLines = 0; btn.titleLabel.textAlignment = NSTextAlignmentCenter; btn.contentEdgeInsets = UIEdgeInsetsMake(10, 16, 10, 16); btn.adjustsImageWhenHighlighted = NO; return btn; } /// 复制统一处理 - (void)kb_copyTextToPasteboard:(NSString *)text { if (text.length == 0) { return; } UIPasteboard.generalPasteboard.string = text; [KBHUD showInfo:KBLocalized(@"Copy Success")]; } /// 点击第一条示例文案 - (void)kb_onTapQ1 { [self kb_copyTextToPasteboard:[self.q1Button titleForState:UIControlStateNormal]]; } /// 点击第二条示例文案 - (void)kb_onTapQ2 { [self kb_copyTextToPasteboard:[self.q2Button titleForState:UIControlStateNormal]]; } @end