輪播圖

#import "ViewController.h"

#import "AppDelegate.h"

#import "NextViewController.h"

@interface ViewController ()

{

UIScrollView *theScroll;

UIPageControl *thePage;

NSArray *theArr;

NSInteger teg;

NSTimer *theTime;

}

@end




@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

float width = self.view.frame.size.width;

float height = self.view.frame.size.height;

theScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, width, height)];

float X = 0.0;

for (int i = 0; i <3; i++)

{

UIImageView *theImg = [[UIImageView alloc]initWithFrame:CGRectMake(X, 0, width, height)];

theArr = @[[UIImage imageNamed:@"666.JPG"],[UIImage imageNamed:@"22.JPG"],[UIImage imageNamed:@"33.JPG"]];

theImg.image = theArr[i];

[theScroll addSubview:theImg];

X += width;

}

theScroll.contentSize = CGSizeMake(width * 3, height);

theScroll.pagingEnabled = YES;

theScroll.showsHorizontalScrollIndicator = NO;

theScroll.delegate = self;

thePage = [[UIPageControl alloc]initWithFrame:CGRectMake(width/2-50, 670, 100, 30)];

thePage.backgroundColor = [UIColor clearColor];

thePage.currentPageIndicatorTintColor = [UIColor redColor];

thePage.numberOfPages = 3;

thePage.currentPage = 0;

[self.view addSubview:theScroll];

[self.view addSubview:thePage];

thePage.currentPage = teg;

theTime = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(scroll) userInfo:nil repeats:YES];

}

- (void)scroll

{

teg ++;

if (teg >= theArr.count)

{

teg = 0;

}

[theScroll setContentOffset:CGPointMake(teg *self.view.frame.size.width, 0) animated:YES];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

CGPoint point = theScroll.contentOffset;

thePage.currentPage = point.x/scrollView.frame.size.width;

UIButton *theBtn = [[UIButton alloc]init];

if (thePage.currentPage == 2)

{

[theTime setFireDate:[NSDate distantFuture]];

theBtn.frame = CGRectMake(180, 620, 100, 40);

[theBtn setTitle:@"立即注冊(cè)" forState:UIControlStateNormal];

[theBtn setTitleColor:[UIColor blueColor] forState: UIControlStateNormal];

[theBtn addTarget:self action:@selector(click) forControlEvents: UIControlEventTouchUpInside ];

[self.view addSubview:theBtn];

}

}

- (void)click

{

NextViewController *next = [[NextViewController alloc]init];

AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;

app.window.rootViewController = next;

}

@end


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容