国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > iOS > 正文

iOS基于UIScrollView實(shí)現(xiàn)滑動(dòng)引導(dǎo)頁(yè)

2020-07-26 02:57:29
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

上代碼前,我們先來(lái)看下實(shí)現(xiàn)的效果圖:

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;   //整頁(yè)滾動(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){       //開(kāi)啟圖片的用戶(hù)點(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];      //加入頁(yè)面指示控件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);   //分頁(yè)面的數(shù)量   pageControl.numberOfPages = IMAGECOUNT;   //設(shè)置小圓點(diǎn)渲染顏色   pageControl.pageIndicatorTintColor = [UIColor whiteColor];   //設(shè)置當(dāng)前選中小圓點(diǎn)的渲染顏色   pageControl.currentPageIndicatorTintColor = [UIColor redColor];   //關(guān)閉用戶(hù)點(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 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 广南县| 八宿县| 南郑县| 宣恩县| 贺兰县| 烟台市| 兴化市| 巩留县| 汉寿县| 皋兰县| 航空| 东丰县| 太和县| 磴口县| 宜城市| 云安县| 卢氏县| 邻水| 米泉市| 合水县| 长兴县| 仁布县| 承德市| 大冶市| 乌什县| 买车| 外汇| 方山县| 五常市| 白山市| 五台县| 黄浦区| 临沭县| 福鼎市| 巴彦淖尔市| 开原市| 新龙县| 班玛县| 澳门| 莱阳市| 东乌|