| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- //
- // KSNormalAlertView.m
- // StudentDaya
- //
- // Created by Kyle on 2020/6/15.
- // Copyright © 2020 DayaMusic. All rights reserved.
- //
- #import "KSNormalAlertView.h"
- typedef enum : NSUInteger {
- ClassRoomAlertViewCancel,
- ClassRoomAlertViewConfirm,
- } ClassRoomAlertViewActionTag;
- #define AWidth 320
- #define AHeight 160
- @interface KSNormalAlertView ()
- @property (nonatomic, strong) UILabel *tipsLabel;
- @property (nonatomic, strong) UILabel *titleLable;
- @property (nonatomic, strong) UIButton *cancelButton;
- @property (nonatomic, strong) UIButton *sureButton;
- @property (nonatomic, strong) NSString *title;
- @property (nonatomic, strong) NSString *leftTitle;
- @property (nonatomic, strong) NSString *rightTitle;
- @property (nonatomic, copy) ButtonCallback cancel;
- @property (nonatomic, copy) ButtonCallback confirm;
- @end
- @implementation KSNormalAlertView
- + (void)ks_showAlertWithTitle:(NSString *)title confirmTitle:(NSString *)confirmTitle confirm:(ButtonCallback)confirm {
- KSNormalAlertView * alertView = [[KSNormalAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds];
- alertView.backgroundColor = HexRGBAlpha(0x000000, 0.5f);
- alertView.title = title;
- alertView.rightTitle = confirmTitle;
- alertView.confirm = confirm;
- [alertView addCancelSubview];
- [alertView showAlertView];
- }
- + (void)ks_showAlertWithTitle:(NSString *)title leftTitle:(NSString *)leftTitle rightTitle:(NSString *)rightTitle cancel:(ButtonCallback)cancel confirm:(ButtonCallback)confirm {
- KSNormalAlertView * alertView = [[KSNormalAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds];
- alertView.backgroundColor = HexRGBAlpha(0x000000, 0.5f);
- alertView.title = title;
- alertView.leftTitle = leftTitle;
- alertView.rightTitle = rightTitle;
- alertView.cancel = cancel;
- alertView.confirm =confirm;
- [alertView addSubviews];
- [alertView showAlertView];
- }
- - (void)showAlertView {
- [[UIApplication sharedApplication].keyWindow addSubview:self];
- }
- -(void)dismissAlertView{
- [self removeFromSuperview];
- }
- - (void)addCancelSubview {
- UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake((UIScreenWidth - AWidth) / 2, (UIScreenHeight - AHeight) / 2, AWidth, AHeight)];
- contentView.backgroundColor = HexRGB(0x161616);
- contentView.layer.cornerRadius = 8;
- contentView.layer.masksToBounds = YES;
- [self addSubview:contentView];
-
- UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, AWidth, 38)];
- topView.backgroundColor = HexRGB(0x222327);
- [contentView addSubview:topView];
- [topView addSubview:self.tipsLabel];
- [self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(topView.mas_left).offset(13);
- make.top.bottom.mas_equalTo(topView);
- make.right.mas_equalTo(topView.mas_right).offset(-13);
- }];
- [contentView addSubview:self.titleLable];
- [contentView addSubview:self.sureButton];
- [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(topView.mas_top).offset(20);
- make.left.equalTo(contentView.mas_left).offset(13);
- make.right.equalTo(contentView.mas_right).offset(-13);
- make.bottom.equalTo(self.sureButton.mas_bottom).offset(-15);
- }];
-
- [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(contentView.mas_bottom).offset(-16);
- make.height.mas_equalTo(26);
- make.width.mas_equalTo(100);
- make.centerX.mas_equalTo(contentView.mas_centerX);
- }];
- }
- - (void)addSubviews {
- UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake((UIScreenWidth - AWidth) / 2, (UIScreenHeight - AHeight) / 2, AWidth, AHeight)];
- contentView.backgroundColor = HexRGB(0x161616);
- contentView.layer.cornerRadius = 8;
- contentView.layer.masksToBounds = YES;
- [self addSubview:contentView];
-
- UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, AWidth, 38)];
- topView.backgroundColor = HexRGB(0x222327);
- [contentView addSubview:topView];
- [topView addSubview:self.tipsLabel];
- [self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(topView.mas_left).offset(13);
- make.top.bottom.mas_equalTo(topView);
- make.right.mas_equalTo(topView.mas_right).offset(-13);
- }];
- [contentView addSubview:self.titleLable];
- [contentView addSubview:self.cancelButton];
- [contentView addSubview:self.sureButton];
- [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(topView.mas_top).offset(20);
- make.left.equalTo(contentView.mas_left).offset(13);
- make.right.equalTo(contentView.mas_right).offset(-13);
- make.bottom.equalTo(self.sureButton.mas_bottom).offset(-15);
- }];
- [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(AWidth/4.0 - 50);
- make.bottom.equalTo(contentView.mas_bottom).offset(-16);
- make.height.mas_equalTo(26);
- make.width.mas_equalTo(100);
- }];
-
- [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(AWidth * 3/4.0 -50);
- make.bottom.mas_equalTo(contentView.mas_bottom).offset(-16);
- make.height.mas_equalTo(26);
- make.width.mas_equalTo(100);
- }];
- }
- - (void)buttonAction:(UIButton *)button {
- if (button.tag == ClassRoomAlertViewCancel) {
- self.cancel();
- }else {
- self.confirm();
- }
- [self dismissAlertView];
- }
- - (UILabel *)tipsLabel {
- if (!_tipsLabel) {
- _tipsLabel = [[UILabel alloc] init];
- _tipsLabel.font = [UIFont systemFontOfSize:16];
- _tipsLabel.textAlignment = NSTextAlignmentLeft;
- _tipsLabel.text = @"提示!";
- _tipsLabel.numberOfLines = 1;
- _tipsLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
- _tipsLabel.textColor = HexRGB(0xf9f9f9);
- }
- return _tipsLabel;
- }
- - (UILabel *)titleLable {
- if (!_titleLable) {
- _titleLable = [[UILabel alloc] init];
- _titleLable.font = [UIFont systemFontOfSize:16];
- _titleLable.textAlignment = NSTextAlignmentLeft;
- _titleLable.text = self.title;
- _titleLable.numberOfLines = 0;
- _titleLable.lineBreakMode = NSLineBreakByTruncatingMiddle;
- _titleLable.textColor = HexRGB(0xf9f9f9);
- }
- return _titleLable;
- }
- - (UIButton *)cancelButton {
- if(!_cancelButton) {
- _cancelButton = [[UIButton alloc] init];
- _cancelButton.backgroundColor = [UIColor clearColor];
- [_cancelButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
- [_cancelButton setTitleColor:HexRGB(0x08f4e6) forState:UIControlStateNormal];
- [_cancelButton setTitle:self.leftTitle forState:UIControlStateNormal];
- _cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
- _cancelButton.tag = ClassRoomAlertViewCancel;
- _cancelButton.layer.cornerRadius = 13.0f;
- _cancelButton.layer.borderWidth = 1.0;
- _cancelButton.layer.borderColor = HexRGB(0x08f4e6).CGColor;
- [_cancelButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
-
- }
- return _cancelButton;
- }
- - (UIButton *)sureButton {
- if (!_sureButton) {
- _sureButton = [[UIButton alloc] init];
- _sureButton.backgroundColor = [UIColor clearColor];
- [_sureButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
- [_sureButton setTitleColor:HexRGB(0x08f4e6) forState:UIControlStateNormal];
- [_sureButton setTitle:self.rightTitle forState:UIControlStateNormal];
- _sureButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
- _sureButton.tag = ClassRoomAlertViewConfirm;
- _sureButton.layer.cornerRadius = 13.0f;
- _sureButton.layer.borderWidth = 1.0;
- _sureButton.layer.borderColor = HexRGB(0x08f4e6).CGColor;
- [_sureButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _sureButton;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|