免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

iOS基于UIScrollView如何實現滑動引導頁-創新互聯

這篇文章將為大家詳細講解有關iOS基于UIScrollView如何實現滑動引導頁,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

網站建設哪家好,找創新互聯!專注于網頁設計、網站建設、微信開發、成都小程序開發、集團企業網站建設等服務項目。為回饋新老客戶創新互聯還提供了萊蕪免費建站歡迎大家使用!

效果圖:

iOS基于UIScrollView如何實現滑動引導頁

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]; 
  //創建ScrollView 
  UIScrollView *sv = [[UIScrollView alloc] init]; 
  sv.frame = self.view.bounds; 
  //設置邊緣不彈跳 
  sv.bounces = NO; 
  //整頁滾動 
  sv.pagingEnabled = YES; 
  sv.showsHorizontalScrollIndicator = NO; 
   
  //加入多個子視圖(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){ 
      //開啟圖片的用戶點擊功能 
      imageView.userInteractionEnabled = YES; 
      //加個按鈕 
      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:@"立即體驗" 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; 
  //設置frame 
  pageControl.frame = CGRectMake(0, self.view.frame.size.height - 40, self.view.frame.size.width, 20); 
  //分頁面的數量 
  pageControl.numberOfPages = IMAGECOUNT; 
  //設置小圓點渲染顏色 
  pageControl.pageIndicatorTintColor = [UIColor whiteColor]; 
  //設置當前選中小圓點的渲染顏色 
  pageControl.currentPageIndicatorTintColor = [UIColor redColor]; 
  //關閉用戶點擊交互 
  pageControl.userInteractionEnabled = NO; 
   
  [self.view addSubview:pageControl]; 
   
  sv.delegate = self; 
   
   
} 
- (void)enter 
{ 
  NSLog(@"進入應用"); 
} 
 
//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

關于“iOS基于UIScrollView如何實現滑動引導頁”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

另外有需要云服務器可以了解下創新互聯建站m.newbst.com,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

新聞標題:iOS基于UIScrollView如何實現滑動引導頁-創新互聯
分享地址:http://m.newbst.com/article0/diodoo.html

成都網站建設公司_創新互聯,為您提供響應式網站微信小程序手機網站建設網站建設外貿建站App開發

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

h5響應式網站建設