From 7b02207537d35bfa1714bf8beafc921f717d100a Mon Sep 17 00:00:00 2001 From: 单军华 Date: Wed, 11 Jul 2018 10:47:42 +0800 Subject: [PATCH] 首次上传 --- screendisplay/Pods/RAlertView/RAlertView/RAlertView.m | 383 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 383 insertions(+), 0 deletions(-) diff --git a/screendisplay/Pods/RAlertView/RAlertView/RAlertView.m b/screendisplay/Pods/RAlertView/RAlertView/RAlertView.m new file mode 100755 index 0000000..9920393 --- /dev/null +++ b/screendisplay/Pods/RAlertView/RAlertView/RAlertView.m @@ -0,0 +1,383 @@ +// +// RAlertView.m +// RAlert +// +// Created by roycms on 2016/10/11. +// Copyright �� 2016��� roycms. All rights reserved. +// + +#import "RAlertView.h" + +@interface RAlertView () + +@property (nonatomic,strong)NSArray *themeArray; + +@end +@implementation RAlertView + + +/** + init + + @param style style description + @return return value description + */ +- (instancetype)initWithStyle:(AlertStyle)style { + self = [super init]; + if (self) { + [self initWindow:style]; + } + return self; +} + +/** + init + + @param style style description + @param width width description + @return return value description + */ +- (instancetype)initWithStyle:(AlertStyle)style width:(CGFloat)width{ + self = [super init]; + if (self) { + [self initWindow:style]; + [self setAlertWidth:width]; + } + return self; +} + +/** + ������������������ + */ +-(void)prepareData{ + + self.themeArray = @[RGB16(0X1abc9c), + RGB16(0X27ae60), + RGB16(0X2980b9), + RGB16(0X2c3e50), + RGB16(0Xf39c12), + RGB16(0Xc0392b), + RGB16(0X7f8c8d), + RGB16(0X8e44ad)]; + + [self.confirmButton setBackgroundColor:self.themeArray[(arc4random() % 8)]]; + [self.confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; +} + +/** + ��������������������� + + @param width width ��������� ������ 0-1 ��������� + */ +-(void)setAlertWidth:(CGFloat)width{ + + [self.mainView mas_updateConstraints:^(MASConstraintMaker *make) { + if (width > 1) { + make.width.offset(width); + } + else if(width > 0 && width <= 1){ + make.width.offset([UIScreen mainScreen].bounds.size.width * width); + } + else{ + make.width.offset([UIScreen mainScreen].bounds.size.width * 0.7); + } + }]; +} + +/** + ������ ��������� set ������ + + @param theme theme description + */ +-(void)setTheme:(UIColor*)theme{ + + [self.confirmButton setBackgroundColor:theme]; + [self.confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; +} + + +/** + ������ ������ ������������������ + + @param isClickBackgroundCloseWindow isClickBackgroundCloseWindow description + */ +-(void)setIsClickBackgroundCloseWindow:(BOOL)isClickBackgroundCloseWindow{ + if(isClickBackgroundCloseWindow){ + UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(exit)]; + [self addGestureRecognizer:tapGesture]; + } +} + +-(void)initWindow:(AlertStyle)style{ + + [self viewInitUI]; + + switch (style) { + case SimpleAlert: + [self simpleAlertViewInitUI]; + break; + case ConfirmAlert: + [self confirmAlertViewInitUI]; + + break; + case CancelAndConfirmAlert: + [self cancelAndConfirmAlertViewInitUI]; + break; + } + + [self animateSenior]; + [self prepareData]; +} + +/** + view ��������� + */ +-(void)viewInitUI{ + + UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; + + [window addSubview:self]; + [self addSubview:self.mainView]; + [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8]]; + [self.mainView insertSubview:self.closedButton atIndex:999]; + [self.mainView addSubview:self.headerTitleLabel]; + [self.mainView insertSubview:self.contentView atIndex:0]; + + [self mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(window); + }]; + self.mainView.translatesAutoresizingMaskIntoConstraints =NO; + + [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) { + make.center.equalTo(self.mainView.superview); + make.width.offset([UIScreen mainScreen].bounds.size.width * 0.7); + }]; + + [self.closedButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.mainView); + make.right.equalTo(self.mainView); + make.width.height.offset(35); + }]; + [self.headerTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.mainView).offset(10); + make.left.equalTo(self.mainView).offset(15); + make.right.equalTo(self.mainView).offset(-30); + }]; + [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.headerTitleLabel.mas_bottom).offset(5); + make.left.equalTo(self.headerTitleLabel); + make.right.equalTo(self.mainView).offset(-15); + make.bottom.equalTo(self.mainView).offset(-10); + }]; +} + +/** + ��������� ������������ + */ +-(void)simpleAlertViewInitUI{ + + [self.contentTextLabel setFont:[UIFont systemFontOfSize:15]]; + [self.contentView addSubview:self.contentTextLabel]; + [self.contentTextLabel sizeToFit]; + + [self.contentTextLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.contentView).offset(10); + make.left.equalTo(self.contentView); + make.right.equalTo(self.contentView); + make.bottom.equalTo(self.contentView).offset(-10); + }]; +} + +/** + ������������������ ��������������� + */ +-(void)confirmAlertViewInitUI{ + + [self.mainView addSubview:self.confirmButton]; + [self.contentView addSubview:self.contentTextLabel]; + + [self.contentTextLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.contentView).offset(10); + make.left.equalTo(self.contentView); + make.right.equalTo(self.contentView); + }]; + [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.contentTextLabel.mas_bottom).offset(10); + make.left.right.equalTo(self.mainView); + make.bottom.equalTo(self.mainView); + make.height.offset(40); + }]; +} + +/** + ��������� ������ ��� ��������������������������� + */ +-(void)cancelAndConfirmAlertViewInitUI{ + [self.mainView addSubview:self.cancelButton]; + [self.mainView addSubview:self.confirmButton]; + [self.contentView addSubview:self.contentTextLabel]; + + [self.contentTextLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.contentView).offset(10); + make.left.equalTo(self.contentView); + make.right.equalTo(self.contentView); + }]; + + NSMutableArray *arrayM = @[].mutableCopy; + [arrayM addObject:self.cancelButton]; + [arrayM addObject:self.confirmButton]; + + [arrayM mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:0 tailSpacing:0]; + [arrayM mas_makeConstraints:^(MASConstraintMaker *make) { + make.height.equalTo(@40); + make.bottom.equalTo(self.mainView); + make.top.equalTo(self.contentTextLabel.mas_bottom).offset(10); + }]; +} + +/** + ������������ ������ + */ +-(void)animate{ + + [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0]]; + [UIView animateWithDuration:0.12 animations:^{ + [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8]]; + }]; + + self.mainView.transform = CGAffineTransformMakeTranslation(0, 600); + [UIView animateWithDuration:0.12 animations:^{ + self.mainView.transform = CGAffineTransformMakeTranslation(0, 0); + }]; +} + +/** + ������������ ������ ������ + */ +-(void)animateSenior{ + + self.mainView.transform = CGAffineTransformMakeTranslation(0, 600); + [UIView animateWithDuration:0.2 delay:0 usingSpringWithDamping:0.35 initialSpringVelocity:0.5 options:UIViewAnimationOptionCurveLinear animations:^{ + self.mainView.transform = CGAffineTransformMakeTranslation(0, 0); + } completion:^(BOOL finished) { + }]; +} + +#pragma make ������ + +/** + ������������ ������ + */ +-(void)exit{ + [self removeFromSuperview]; +} + +/** + ������������������ + + @param sender sender description + */ +-(void)closedButtonClick:(UIButton *)sender{ + [self exit]; +} + +/** + ��������������������� + + @param sender sender description + */ +-(void)confirmButtonClick:(UIButton*)sender{ + + if(self.confirm){ + self.confirm(); + } + [self exit]; +} + +/** + ��������������� ������ + + @param sender sender description + */ +-(void)cancelButtonClick:(UIButton*)sender{ + if(self.cancel){ + self.cancel(); + } + [self exit]; +} + +#pragma make ��������� + +-(UIView*)mainView{ + if (_mainView == nil) { + _mainView = [[UIView alloc]init]; + [_mainView setBackgroundColor:[UIColor whiteColor]]; + [_mainView.layer setMasksToBounds:YES]; + [_mainView.layer setCornerRadius:4]; + } + return _mainView; +} +-(UIButton *)confirmButton{ + if(_confirmButton == nil){ + _confirmButton = [[UIButton alloc]init]; + [_confirmButton setBackgroundColor:RGB16(0Xfddb43)]; + [_confirmButton setTitle:@"Ok" forState:UIControlStateNormal]; + [_confirmButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + [_confirmButton setTitleColor:RGB16(0X3d3d3d) forState:UIControlStateNormal]; + [_confirmButton.titleLabel setFont:[UIFont systemFontOfSize:15]]; + [_confirmButton addTarget:self action:@selector(confirmButtonClick:) forControlEvents:UIControlEventTouchUpInside]; + } + return _confirmButton; +} +-(UIButton *)cancelButton{ + if(_cancelButton == nil){ + _cancelButton = [[UIButton alloc]init]; + [_cancelButton setBackgroundColor:RGB16(0XEBECED)]; + [_cancelButton setTitle:@"Cancel" forState:UIControlStateNormal]; + [_cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + [_cancelButton setTitleColor:RGB16(0X3d3d3d) forState:UIControlStateNormal]; + [_cancelButton.titleLabel setFont:[UIFont systemFontOfSize:15]]; + [_cancelButton addTarget:self action:@selector(cancelButtonClick:) forControlEvents:UIControlEventTouchUpInside]; + } + return _cancelButton; +} + +-(UIButton *)closedButton{ + if(_closedButton == nil){ + _closedButton = [[UIButton alloc]init]; + [_closedButton setImage:[UIImage imageNamed:@"closed.png"] forState:UIControlStateNormal]; + [_closedButton addTarget:self action:@selector(closedButtonClick:) forControlEvents:UIControlEventTouchUpInside]; + } + return _closedButton; +} + +-(UILabel*)headerTitleLabel { + if (_headerTitleLabel == nil) { + _headerTitleLabel = [[UILabel alloc]init]; + [_headerTitleLabel setFont:[UIFont systemFontOfSize:15]]; + [_headerTitleLabel setTextAlignment:NSTextAlignmentCenter]; + [_headerTitleLabel setTextColor:RGB16(0X3d3d3d)]; + } + return _headerTitleLabel; +} + +-(UIView *)contentView{ + if(_contentView==nil){ + _contentView =[[UIView alloc]init]; + [_contentView setBackgroundColor:[UIColor whiteColor]]; + } + return _contentView; +} + +-(UILabel*)contentTextLabel { + if (_contentTextLabel == nil) { + _contentTextLabel = [[UILabel alloc]init]; + [_contentTextLabel setFont:[UIFont systemFontOfSize:13]]; + [_contentTextLabel setTextAlignment:NSTextAlignmentCenter]; + [_contentTextLabel setTextColor:RGB16(0X898989)]; + _contentTextLabel.numberOfLines = 0; + } + return _contentTextLabel; +} + +@end -- Gitblit v1.8.0