1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- //
- // KSNewConfirmAlertView.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2023/9/26.
- //
- #import "KSNewConfirmAlertView.h"
- #import <KSToolLibrary/UIView+Animation.h>
- @interface KSNewConfirmAlertView ()
- @property (nonatomic, copy) KSConfirmAlertCallback callback;
- @property (weak, nonatomic) IBOutlet UILabel *headTitle;
- @property (weak, nonatomic) IBOutlet UILabel *descLabel;
- @property (weak, nonatomic) IBOutlet UIButton *sureButton;
- @end
- @implementation KSNewConfirmAlertView
- - (void)awakeFromNib {
- [super awakeFromNib];
- [self.sureButton setBackgroundColor:THEMECOLOR];
- }
- + (instancetype)shareInstance {
- KSNewConfirmAlertView *view = [[[NSBundle mainBundle] loadNibNamed:@"KSNewConfirmAlertView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)configTitle:(NSString *)title desc:(NSString *)desc callback:(KSConfirmAlertCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- [self.headTitle setText:title];
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:4];//调整行间距
- [paragraphStyle setAlignment:NSTextAlignmentCenter];
- NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:[NSString returnNoNullStringWithString:desc] attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:16.0f],NSForegroundColorAttributeName:HexRGB(0x666666)}];
- self.descLabel.attributedText = attrStr;
- }
- - (void)showAlert {
- UIWindow *window = [NSObject getKeyWindow];
- [window addSubview:self];
- [self mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(window);
- }];
-
- [self setPopAnimation];
- }
- - (void)hiddenAction {
- [self removeFromSuperview];
- }
- - (IBAction)sureAction:(id)sender {
- if (self.callback) {
- self.callback(YES);
- }
- [self hiddenAction];
- }
- - (IBAction)cancleAction:(id)sender {
- if (self.callback) {
- self.callback(NO);
- }
- [self hiddenAction];
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|