123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- //
- // FKExitOrdersRemindView.m
- // FirstLink
- //
- // Created by 施昌鹏 on 16/7/12.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKExitRemindView.h"
- @interface FKExitRemindView ()
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) UIImageView *cartoonImageView;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UIButton *confirmButton;
- @property (nonatomic, strong) UIButton *cancelButton;
- @property (nonatomic, strong) UIView *divideViewH;
- @property (nonatomic, strong) UIView *divideViewV;
- @end
- @implementation FKExitRemindView
- -(instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self addSubviews];
- self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
- }
- return self;
- }
- -(void)addSubviews {
- [self addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self);
- make.height.mas_equalTo(130);
- make.width.mas_equalTo(255);
- }];
-
- [self addSubview:self.cartoonImageView];
- [self.cartoonImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.bgView.mas_centerX);
- make.bottom.equalTo(self.bgView.mas_top).offset(23);
- }];
-
- [self.bgView addSubview:self.titleLabel];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.equalTo(self.bgView);
- make.height.mas_equalTo(80);
- }];
-
- [self.bgView addSubview:self.confirmButton];
- [self.bgView addSubview:self.cancelButton];
- [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.bottom.equalTo(self.bgView);
- make.top.equalTo(self.titleLabel.mas_bottom).offset(0.5);
- make.left.equalTo(self.confirmButton.mas_right).offset(0.5);
- make.width.equalTo(self.confirmButton);
- }];
-
-
- [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.equalTo(self.bgView);
- make.top.equalTo(self.cancelButton);
- make.width.equalTo(self.cancelButton);
- }];
-
- [self.bgView addSubview:self.divideViewH];
- [self.divideViewH mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.bgView);
- make.top.equalTo(self.titleLabel.mas_bottom);
- make.height.mas_equalTo(0.5);
- }];
-
- [self.bgView addSubview:self.divideViewV];
- [self.divideViewV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.divideViewH.mas_bottom);
- make.bottom.equalTo(self.bgView);
- make.centerX.equalTo(self.bgView);
- make.width.mas_equalTo(0.5);
- }];
-
- }
- + (instancetype)initWithTitleString:(NSString *)titleString confirmButtonText:(NSString *)confirmText cancelButtonText:(NSString *)cancelText{
- FKExitRemindView *view = [[FKExitRemindView alloc]init];
- view.titleLabel.text = titleString;
- [view.confirmButton setTitle:confirmText forState:UIControlStateNormal];
- [view.cancelButton setTitle:cancelText forState:UIControlStateNormal];
- return view;
- }
- -(void)clickButton:(UIButton *)button {
- self.alpha = 1.0f;
-
- if ([_delegate respondsToSelector:@selector(exitRemindView:clickedButtonAtIndex:)]) {
- [_delegate exitRemindView:self clickedButtonAtIndex:button.tag];
- }
-
- WeakSelf(weakSelf);
- [UIView animateWithDuration:0.3f animations:^{
- weakSelf.alpha = 0;
- } completion:^(BOOL finished) {
- [weakSelf removeFromSuperview];
- }];
-
- }
- -(void)showInView:(UIView *)view {
- UIWindow *window = view.window;
- [window addSubview:self];
- self.alpha = 0;
- self.frame = CGRectMake(0, 0, window.bounds.size.width, window.bounds.size.height);
-
- WeakSelf(weakSelf);
- [UIView animateWithDuration:0.3f animations:^{
- weakSelf.alpha = 1.0;
- } completion:nil];
- }
- - (void)setLogoHidden:(BOOL)hidden {
- self.cartoonImageView.hidden = hidden;
- }
- #pragma mark - get
- -(UIView *)bgView {
- if (_bgView == nil) {
- _bgView = [[UIView alloc] init];
- _bgView.backgroundColor = [UIColor whiteColor];
- _bgView.layer.cornerRadius = 8.0;
- }
- return _bgView;
- }
- -(UIImageView *)cartoonImageView {
- if (_cartoonImageView == nil) {
- UIImage *cartoonImage = [UIImage imageNamed:@"cartoon_icon"];
- _cartoonImageView = [[UIImageView alloc] initWithImage:cartoonImage];
- }
- return _cartoonImageView;
- }
- -(UILabel *)titleLabel {
- if (_titleLabel == nil) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.font = [UIFont systemFontOfSize:15.0];
- _titleLabel.textColor = UIColorFromRGB(0x333333);
- _titleLabel.textAlignment = NSTextAlignmentCenter;
- _titleLabel.numberOfLines = 2;
- }
- return _titleLabel;
- }
- -(UIButton *)cancelButton {
- if (_cancelButton == nil) {
- _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _cancelButton.tag = 1;
- [_cancelButton setTitleColor:UIColorFromRGB(0xff6362) forState:UIControlStateNormal];
- [_cancelButton.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
- [_cancelButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
-
- }
- return _cancelButton;
- }
- -(UIButton *)confirmButton {
- if (_confirmButton == nil) {
- _confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _confirmButton.tag = 0;
- [_confirmButton setTitleColor:UIColorFromRGB(0x999999) forState:UIControlStateNormal];
- [_confirmButton.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
- [_confirmButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
-
- }
- return _confirmButton;
- }
- -(UIView *)divideViewH {
- if (_divideViewH == nil) {
- _divideViewH = [[UIView alloc] init];
- _divideViewH.backgroundColor = UIColorFromRGB(0xe5e5e5);
- }
- return _divideViewH;
- }
- -(UIView *)divideViewV {
- if (_divideViewV == nil) {
- _divideViewV = [[UIView alloc] init];
- _divideViewV.backgroundColor = UIColorFromRGB(0xe5e5e5);
- }
- return _divideViewV;
- }
- @end
|