123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- //
- // MergeTipsAlert.m
- // KulexiuSchoolStudent
- //
- // Created by 王智 on 2024/7/15.
- //
- #import "MergeTipsAlert.h"
- @interface MergeTipsAlert ()
- @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
- @property (weak, nonatomic) IBOutlet UIButton *leftButton;
- @property (weak, nonatomic) IBOutlet UIButton *rightButton;
- @property (nonatomic, copy) MergeTipsCallback cancelCallback;
- @property (nonatomic, copy) MergeTipsCallback sureCallback;
- @end
- @implementation MergeTipsAlert
- - (void)awakeFromNib {
- [super awakeFromNib];
- }
- + (instancetype)shareInstance {
- MergeTipsAlert *view = [[[NSBundle mainBundle] loadNibNamed:@"MergeTipsAlert" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)configWithDesc:(NSString *)desc leftTitle:(NSString *)leftTitle rightTitle:(NSString *)rightTitle {
- if ([NSString isEmptyString:desc]) {
- desc = @"";
- }
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:4];//调整行间距
- paragraphStyle.alignment = NSTextAlignmentCenter;
- paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
- NSMutableAttributedString *tipsAttrs = [[NSMutableAttributedString alloc] initWithString:desc attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16.0f weight:UIFontWeightRegular], NSForegroundColorAttributeName:HexRGB(0x777777),NSParagraphStyleAttributeName:paragraphStyle}];
- self.tipsLabel.attributedText = tipsAttrs;
- if (![NSString isEmptyString:leftTitle]) {
- [self.leftButton setTitle:leftTitle forState:UIControlStateNormal];
- }
- if (![NSString isEmptyString:rightTitle]) {
- [self.rightButton setTitle:rightTitle forState:UIControlStateNormal];
- }
- [self layoutIfNeeded];
- }
- - (void)actionCallbackCancel:(MergeTipsCallback)cancel sure:(MergeTipsCallback)sure {
-
- if (cancel) {
- self.cancelCallback = cancel;
- }
- if (sure) {
- self.sureCallback = sure;
- }
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- }
- - (void)showAlert {
- UIView *displayView = [NSObject getKeyWindow];
- [displayView addSubview:self];
- [self mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(displayView);
- }];
- }
- - (IBAction)cancelAction:(id)sender {
- [self removeFromSuperview];
- if (self.cancelCallback) {
- self.cancelCallback();
- }
- }
- - (IBAction)sureAction:(id)sender {
- [self removeFromSuperview];
- if (self.sureCallback) {
- self.sureCallback();
- }
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|