1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- //
- // KSPublicAlertView.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/6/28.
- //
- #import "KSPublicAlertView.h"
- #import <KSToolLibrary/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
- - (void)awakeFromNib {
- [super awakeFromNib];
- [self.cancleButton setTitleColor:CLIENT_THEMECOLOR forState:UIControlStateNormal];
- self.cancleButton.layer.borderColor = CLIENT_THEMECOLOR.CGColor;
- [self.sureButton setBackgroundColor:CLIENT_THEMECOLOR];
- }
- + (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;
-
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:4];//调整行间距
- paragraphStyle.alignment = NSTextAlignmentCenter;
- NSMutableAttributedString *attrs = [[NSMutableAttributedString alloc] initWithString:descMsg attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:16.0f],NSForegroundColorAttributeName:HexRGB(0x666666)}];
- alertView.descLabel.attributedText = attrs;
-
- [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
|