UIScrollView、UIPageControl

來源:互聯網
上載者:User
 //建立滾動視圖    scroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];    scroll.pagingEnabled=YES;//設定翻頁效果    scroll.showsHorizontalScrollIndicator=NO;//不顯示水平捲軸    scroll.delegate=self;    scroll.contentSize=CGSizeMake(320*NUM, 460);//內容大小    for (int i=0; i<NUM; i++) {        UIImageView * imgView=[[UIImageView alloc] initWithFrame:CGRectMake(i*320, 0, 320, 460)];        UIImage * img=[UIImage imageNamed:@"IMG_0012.JPG"];        imgView.image=img;        [scroll addSubview:imgView];        [imgView release];    }    [self.view addSubview:scroll];    [scroll release];---------------------------------------------------------    //建立分頁檢視    page=[[UIPageControl alloc] initWithFrame:CGRectMake(0, 350, 320, 60)];    page.numberOfPages=NUM;//頁碼數    page.pageIndicatorTintColor=[UIColorblackColor];//非當前頁的點顏色    page.currentPageIndicatorTintColor=[UIColorblueColor];//當前頁的點顏色    [pageaddTarget:selfaction:@selector(pageEventAction:) forControlEvents:UIControlEventValueChanged];//添加事件處理    [self.view addSubview:page];    [page release];-----------------------------------------------------------//滾動視圖跟分頁控制器關聯-(void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView{    CGPoint p=scrollView.contentOffset;//位移量    int n=p.x/320;    page.currentPage=n;//當前頁碼}//點擊分頁檢視觸發事件-(void) pageEventAction:(UIPageControl *) sender{    scroll.contentOffset=CGPointMake(sender.currentPage*320, 0);}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.