启动页分为4页,最后一页有一个按钮,点击跳转到主页面_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > 启动页分为4页,最后一页有一个按钮,点击跳转到主页面

启动页分为4页,最后一页有一个按钮,点击跳转到主页面

 2014/10/14 12:44:30  粉粉色  程序员俱乐部  我要评论(0)
  • 摘要:代码效果为:启动页分为4页,最后一页有一个按钮,点击跳转到主页面。上代码:-(void)viewDidLoad{[superviewDidLoad];//Doanyadditionalsetupafterloadingtheview.UIScrollView*sv=[[UIScrollViewalloc]initWithFrame:CGRectMake(0,0,320,460)];sv.contentSize=CGSizeMake(320*4,460);sv.pagingEnabled=YES
  • 标签:一个 启动

 

代码效果为:启动页分为4页,最后一页有一个按钮,点击跳转到主页面。

 

上代码:

 

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIScrollView * sv = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    sv.contentSize = CGSizeMake(320 * 4, 460);
    sv.pagingEnabled = YES;
    sv.showsHorizontalScrollIndicator = NO;
    sv.delegate = self;
    sv.tag = 1;
    [self.view addSubview:sv];
    
    UIPageControl * pc = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 420, 320, 20)];
    pc.numberOfPages = 4;
    [pc addTarget:self action:@selector(pc:) forControlEvents:UIControlEventTouchUpInside];
    pc.tag = 2;
    [self.view addSubview:pc];
    
    for(int i = 0; i < 4; i++){
        UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"start%d.png",i+1]]];
        imageView.frame = CGRectMake(320 * i, 0, 320, 460);
        [sv addSubview:imageView];
    }
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(320*3+100, 380, 164, 42);
    [button setImage:[UIImage imageNamed:@"anniu.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
    [sv addSubview:button];

}
#pragma -mark -doClickAction
-(void)pc:(UIPageControl *)pc
{
    UIScrollView * sv = (UIScrollView *)[self.view viewWithTag:1];
    sv.contentOffset = CGPointMake(pc.currentPage*320, 0);
}
-(void)start
{
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"开始" message:nil delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma -mark -UISCrollerViewDelegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    UIPageControl * pc = (UIPageControl *)[self.view viewWithTag:2];
    pc.currentPage = scrollView.contentOffset.x/320;
}

 

发表评论
用户名: 匿名