码迷,mamicode.com
首页 > 其他好文 > 详细

简单弹出视图

时间:2014-05-01 08:14:54      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   tar   javascript   ext   get   color   set   

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;
    }
 ];
}

  

mamicode.com,码迷
#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
mamicode.com,码迷

 

简单弹出视图,码迷,mamicode.com

简单弹出视图

标签:style   blog   class   code   java   tar   javascript   ext   get   color   set   

原文地址:http://www.cnblogs.com/hl666/p/3701893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!