123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- //
- // KSPublicAlertView.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/6/28.
- //
- #import "KSPublicAlertView.h"
- #import "UIView+Animation.h"
- @interface KSPublicAlertView ()
- @property (weak, nonatomic) IBOutlet UILabel *topTitle;
- @property (weak, nonatomic) IBOutlet UILabel *descLabel;
- @property (weak, nonatomic) IBOutlet UIButton *cancleButton;
- @property (weak, nonatomic) IBOutlet UIButton *sureButton;
- @property (nonatomic, copy) AlertCallback cancelCallback;
- @property (nonatomic, copy) AlertCallback sureCallback;
- @end
- @implementation KSPublicAlertView
- + (instancetype)shareInstanceWithTitle:(NSString *)title descMessage:(NSString *)descMsg leftTitle:(NSString *)leftTitle rightTitle:(NSString *)rightTitle cancelAction:(AlertCallback)cancelCallback sureAction:(AlertCallback)sureCallback {
- KSPublicAlertView *alertView = [[[NSBundle mainBundle] loadNibNamed:@"KSPublicAlertView" owner:nil options:nil] firstObject];
- alertView.topTitle.text = title;
- alertView.descLabel.text = descMsg;
- [alertView.cancleButton setTitle:leftTitle forState:UIControlStateNormal];
- [alertView.sureButton setTitle:rightTitle forState:UIControlStateNormal];
- if (cancelCallback) {
- alertView.cancelCallback = cancelCallback;
- }
- if (sureCallback) {
- alertView.sureCallback = sureCallback;
- }
- [alertView showAlert];
- return alertView;
- }
- - (void)showAlert {
- [[NSObject getKeyWindow] addSubview:self];
- [self mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.bottom.right.mas_equalTo([NSObject getKeyWindow]);
- }];
- [self setPopAnimation];
- }
- - (void)hiddenAction {
- [self removeFromSuperview];
- }
- - (IBAction)cancleAction:(id)sender {
- if (self.cancelCallback) {
- self.cancelCallback();
- }
- [self hiddenAction];
- }
- - (IBAction)sureAction:(id)sender {
- if (self.sureCallback) {
- self.sureCallback();
- }
- [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
|