archive不弹框 ios
ios弹框
2017-08-31 14:26:00 weixin_33923148 阅读数 40
第一种
    
    UIAlertController *aler=[UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确定取消?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *ok=[UIAlertAction actionWithTitle:@"确定取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }];
    UIAlertAction *cancel=[UIAlertAction actionWithTitle:@"暂不取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
           
    }];
    //设置按钮字体颜色
    [cancel setValue:[UIColor redColor] forKey:@"_titleTextColor"];
    [aler addAction:cancel];
    //添加
    [aler addAction:ok];
    //最后一步
    [self presentViewController:aler animated:YES completion:nil];
    

第二种


    UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                  message:@"确定取消?"
                                                 delegate:self
                                        cancelButtonTitle:@"暂不取消"
                                        otherButtonTitles:@"确定取消",nil];
    [alert show];
    


代理方法

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==1) {
    }
    NSLog(@"您按下的第%ld个按钮!",buttonIndex);
}

2015-11-09 10:38:17 iotjin 阅读数 166

    //弹框    

    

    UIAlertController *sheetController = [UIAlertController alertControllerWithTitle:@"标题" message:nil preferredStyle:UIAlertControllerStyleAlert];


    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

        //选中确定之后的操作


            NSLog(@" 确定  ");



    }];



    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];


    [sheetController addAction:okAction];

    [sheetController addAction:cancelAction];


    [self presentViewController:sheetController animated:YES completion:^{

        //完成之后的操作





    }];

2013-11-03 09:31:40 u011206291 阅读数 768
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    
    UIButton *btn1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn1 setTitle:@"Alert" forState:UIControlStateNormal];
    btn1.frame=CGRectMake(10, 100, 100, 40);
    [btn1 addTarget:self action:@selector(AlertViewShow) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:btn1];
    
    
    UIButton *btn2=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn2 setTitle:@"ActionSheet" forState:UIControlStateNormal];
    btn2.frame=CGRectMake(210, 100, 100, 40);
    [btn2 addTarget:self action:@selector(ActionSheetShow) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:btn2];
    
    
    
    return YES;
}

-(void)AlertViewShow
{
    UIAlertView *pAlert=[[UIAlertView alloc]initWithTitle:@"警告" message:@"this is alertView" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"sure", nil];
    [pAlert show];
    [pAlert release];
}

-(void)ActionSheetShow
{
    UIActionSheet *pSheet=[[UIActionSheet alloc]initWithTitle:@"ActionView" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"确定" otherButtonTitles:@"第一页",@"第二页", nil];
    
    [pSheet showInView:self.window];
    
    [pSheet release];
}

2017-04-19 16:50:00 weixin_34358365 阅读数 19

1、系统弹框-底部弹框 UIActionSheet

  • 1、用法
处理用户非常危险的操作,比如注销系统等。
  • 2、举例
UIActionSheet *sheet = [[UIActionSheet alloc] 
                          initWithTitle:@“确定要注销?”
                               delegate:self 
                      cancelButtonTitle:@“取消” 
                 destructiveButtonTitle:@“确定” 
                      otherButtonTitles:nil, nil];
[sheet showInView:self.view];

如图1:

2189973-e18672b034e50ee1
图1.png

2、系统弹框-中间弹框 UIAlertView

  • 1、用法
处理一般提醒,如果非必须,尽量不用,影响友好性。
  • 2、举例
UIAlertView *alert = [[UIAlertView alloc] 
                             initWithTitle:@“警告” 
                                   message:@“账号或者密码错误” 
                                  delegate:nil
                         cancelButtonTitle:@“好的” 
                         otherButtonTitles:nil, nil];
[alert show];

如图2:


2189973-e0077a6b1b2a0be4
图2.png

在登陆界面,输入账号密码,如果有一项输入错误,弹框提示,必须点击“好的”才能重新输入

2017-10-25 22:51:00 weixin_33978016 阅读数 16

一个可以自定义弹出视图内容,弹出视图所在位置的小轮子。

#import "CommanBottomPopView.h"

#define LC_ACTION_SHEET_COLOR(r, g, b)      [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1.0f]

@interface CommanBottomPopView ()

@property(nonatomic, weak) UIView *darkView;
@property(nonatomic, weak) UIView *customView;

@end

@implementation CommanBottomPopView

+ (instancetype)bottomPopWithCustomView:(UIView *)customView positionState:(PositionState)state{
    return [[self alloc] initWithCustomView:customView positionState:state];
}

- (instancetype)initWithCustomView:(UIView *)customView positionState:(PositionState)state{
    if (self = [super init]) {
        self.customView = customView;
        [self setupViewWithPosition:state];
    }
    return self;
}

- (void)setupViewWithPosition:(PositionState)state {
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    [keyWindow addSubview:self];
    [self makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(keyWindow);
    }];
    if (self.customView) {
        UIView *darkView = [[UIView alloc] init];
        darkView.alpha = 0;
        darkView.userInteractionEnabled = NO;
        darkView.backgroundColor = LC_ACTION_SHEET_COLOR(46, 49, 50);
        [self addSubview:darkView];
        [darkView makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(@(0));
        }];
        self.darkView = darkView;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(darkViewClicked)];
        [darkView addGestureRecognizer:tap];
        [self addSubview:self.customView];
        
        CGFloat height = CGRectGetHeight(self.customView.frame);
        CGFloat width = CGRectGetWidth(self.customView.frame);
        CGFloat top = [UIScreen mainScreen].bounds.size.height - height;
        
        
        if (state == PositionStateCenter) {
            [self.customView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.centerX.mas_equalTo(self.mas_centerX);
                make.centerY.mas_equalTo(self.mas_centerY);
                make.height.mas_equalTo(@(height));
                make.width.mas_equalTo(@(width));
            }];
        } else if (state == PositionStateBottom) {
            [self.customView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(@(top));
                make.centerX.mas_equalTo(self.mas_centerX);
                make.height.mas_equalTo(@(height));
                make.width.mas_equalTo(@(width));
            }];
        } else {
            
        }
    
        self.customView.hidden = YES;
        return;
    }
}

- (void)darkViewClicked {
    [self hideSelf];
}

- (void)show {
    [self layoutIfNeeded];
    __weak typeof (self) weakSelf = self;
    [UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        weakSelf.darkView.alpha = .4;
        weakSelf.darkView.userInteractionEnabled = YES;
        if (weakSelf.customView) {
            weakSelf.customView.hidden = NO;
        }
        [weakSelf layoutIfNeeded];
    } completion:^(BOOL finished) {
        
    }];
}

- (void)hideSelf {
    __weak typeof (self) weakSelf = self;
    [UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        weakSelf.darkView.alpha = 0;
        weakSelf.darkView.userInteractionEnabled = NO;
        if (weakSelf.customView) {
            weakSelf.customView.hidden = YES;
        }
        [weakSelf layoutIfNeeded];
    } completion:^(BOOL finished) {
        [weakSelf removeFromSuperview];
    }];
}

- (void)dealloc {
    NSLog(@"dealloc -- %@", [self class]);
}

使用:

- (void)popView {
    self.customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)];
    self.customView.backgroundColor = [UIColor redColor];
    self.popBgView = [CommanBottomPopView bottomPopWithCustomView:self.customView positionState:PositionStateCenter];
    [self.popBgView show];
}

仿ios的弹框

阅读数 134

没有更多推荐了,返回首页