你好,歡迎來到IOS教程網

 Ios教程網 >> IOS使用技巧 >> IOS技巧綜合 >> 啟動頁分為4頁,最後一頁有一個按鈕,點擊跳轉到主頁面

啟動頁分為4頁,最後一頁有一個按鈕,點擊跳轉到主頁面

編輯:IOS技巧綜合
[摘要]本文是對啟動頁分為4頁,最後一頁有一個按鈕,點擊跳轉到主頁面的講解,對學習IOS蘋果軟件開發有所幫助,與大家分享。

代碼效果為:啟動頁分為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;
}
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved