這篇文章將為大家詳細(xì)講解有關(guān)iOS基于UIScrollView如何實(shí)現(xiàn)滑動(dòng)引導(dǎo)頁,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、成都小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了萊蕪免費(fèi)建站歡迎大家使用!效果圖:
WelcomeViewController.h
#import <UIKit/UIKit.h> @interface WelcomeViewController : UIViewController @end
WelcomeViewController.m
#import "WelcomeViewController.h" #define IMAGECOUNT 3 @interface WelcomeViewController () <UIScrollViewDelegate> @property (nonatomic, strong)UIPageControl *pageControl; @end @implementation WelcomeViewController - (void)viewDidLoad { [super viewDidLoad]; //創(chuàng)建ScrollView UIScrollView *sv = [[UIScrollView alloc] init]; sv.frame = self.view.bounds; //設(shè)置邊緣不彈跳 sv.bounces = NO; //整頁滾動(dòng) sv.pagingEnabled = YES; sv.showsHorizontalScrollIndicator = NO; //加入多個(gè)子視圖(ImageView) for(NSInteger i=0; i<IMAGECOUNT; i++){ NSString *imgName = [NSString stringWithFormat:@"%ld", i+1]; UIImage *image = [UIImage imageNamed:imgName]; UIImageView *imageView = [[UIImageView alloc]initWithImage:image]; CGRect frame = CGRectZero; frame.origin.x = i * sv.frame.size.width; frame.size = sv.frame.size; imageView.frame = frame; [sv addSubview:imageView]; if(i==IMAGECOUNT-1){ //開啟圖片的用戶點(diǎn)擊功能 imageView.userInteractionEnabled = YES; //加個(gè)按鈕 UIButton *button = [[UIButton alloc]init]; button.frame = CGRectMake((imageView.frame.size.width-150)/2, imageView.frame.size.height*0.8, 150, 40); button.backgroundColor = [UIColor orangeColor]; [button setTitle:@"立即體驗(yàn)" forState:UIControlStateNormal]; button.titleLabel.font = [UIFont boldSystemFontOfSize:16]; [imageView addSubview:button]; [button addTarget:self action:@selector(enter) forControlEvents:UIControlEventTouchUpInside]; } } sv.contentSize = CGSizeMake(IMAGECOUNT * sv.frame.size.width, sv.frame.size.height); [self.view addSubview:sv]; //加入頁面指示控件PageControl UIPageControl *pageControl = [[UIPageControl alloc]init]; self.pageControl = pageControl; //設(shè)置frame pageControl.frame = CGRectMake(0, self.view.frame.size.height - 40, self.view.frame.size.width, 20); //分頁面的數(shù)量 pageControl.numberOfPages = IMAGECOUNT; //設(shè)置小圓點(diǎn)渲染顏色 pageControl.pageIndicatorTintColor = [UIColor whiteColor]; //設(shè)置當(dāng)前選中小圓點(diǎn)的渲染顏色 pageControl.currentPageIndicatorTintColor = [UIColor redColor]; //關(guān)閉用戶點(diǎn)擊交互 pageControl.userInteractionEnabled = NO; [self.view addSubview:pageControl]; sv.delegate = self; } - (void)enter { NSLog(@"進(jìn)入應(yīng)用"); } //UIScrollViewDelegate方法 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGPoint offset = scrollView.contentOffset; if(offset.x<=0){ offset.x = 0; scrollView.contentOffset = offset; } NSUInteger index = round(offset.x / scrollView.frame.size.width); self.pageControl.currentPage = index; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
關(guān)于“iOS基于UIScrollView如何實(shí)現(xiàn)滑動(dòng)引導(dǎo)頁”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站bm7419.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
新聞標(biāo)題:iOS基于UIScrollView如何實(shí)現(xiàn)滑動(dòng)引導(dǎo)頁-創(chuàng)新互聯(lián)
分享地址:http://bm7419.com/article0/diodoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、微信小程序、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、外貿(mào)建站、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容