首页 > 代码库 > 简单弹出视图
简单弹出视图
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #import "loveView.h" //点击按钮 -( void )buttonclick { UIWindow *window = [UIApplication sharedApplication].keyWindow; loveView *loveview = [[loveView alloc] initWithFrame:window.bounds]; loveview.alpha = 0; [window.rootViewController.view addSubview:loveview]; [UIView animateWithDuration:0.5 animations:^{ loveview.alpha = 1.0; } ]; } |
#import "loveView.h" @implementation loveView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code [self creatView]; } return self; } -(void)creatView { [self setBackgroundColor:[UIColor clearColor]]; UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)]; backView.center = self.center; [backView setBackgroundColor:[UIColor blackColor]]; [self addSubview:backView]; backView.alpha = 0.3; UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 200)]; mainView.center = self.center; [mainView setBackgroundColor:[UIColor whiteColor]]; [self addSubview:mainView]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10,260, 50)]; label.text = @" Love Me?那就告诉全世界吧!"; label.backgroundColor = [UIColor clearColor]; label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor blueColor]; UIButton *yesBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 60, 260, 50)]; [yesBtn setBackgroundColor:[UIColor greenColor]]; [yesBtn setTitle:@"好!" forState:UIControlStateNormal]; [yesBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; [yesBtn addTarget:self action:@selector(yesBtnClick) forControlEvents:UIControlEventTouchUpInside]; UIButton *noBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 130, 260, 50)]; [noBtn setBackgroundColor:[UIColor redColor]]; [noBtn setTitle:@"不,谢谢" forState:UIControlStateNormal]; [noBtn addTarget:self action:@selector(noBtnClick) forControlEvents:UIControlEventTouchUpInside]; [mainView addSubview:label]; [mainView addSubview:yesBtn]; [mainView addSubview:noBtn]; } - (void)yesBtnClick { NSLog(@"YES!!!"); [UIView animateWithDuration:0.5 animations:^{ self.alpha = 0.0; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } - (void)noBtnClick { NSLog(@"NO!!!"); [UIView animateWithDuration:0.5 animations:^{ self.alpha = 0.0; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } @end
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。