ios 輪播圖

#import "ViewController.h"

#import "oneViewController.h"

@interface ViewController (){

UIScrollView *theSceo;

NSArray *theArr;

UIPageControl *thePage;

}

@end

@implementation ViewController

- (void)viewDidLoad {

? ? ? ? ? ? [super viewDidLoad];

? ? ? ? ? ? self.view.backgroundColor = [UIColor whiteColor];

? ? ? ? ? ? //初始化滾動(dòng)視圖

? ? ? ?theSceo = [[UIScrollView alloc]initWithFrame:self.view.frame];

? ? ? ? //設(shè)置代理

? ? ?theSceo.delegate = self;

? ? ? //設(shè)置按頁滾動(dòng)

? ? theSceo.pagingEnabled = YES;

? ? //設(shè)置是否顯示滾動(dòng)條

? ? theSceo.showsHorizontalScrollIndicator = NO;

? ? //添加到視圖

[self.view addSubview:theSceo];

theArr = @[@"1.jpeg",@"2.jpeg",@"3.jpeg",@"4.jpeg"];

CGFloat x = 0.0

theSceo.contentSize = CGSizeMake(x, self.view.frame.size.height);

//初始化一個(gè)分頁控制器

thePage = [[UIPageControl alloc]initWithFrame:CGRectMake((self.view.frame.size.width)/2-30, self.view.frame.size.height/5*4, 60, 20)];

//設(shè)置分頁控制器個(gè)數(shù)

thePage.numberOfPages = theArr.count;

//設(shè)置分頁控制器的 顏色

thePage.pageIndicatorTintColor = [UIColor whiteColor];

//社會(huì)化做分頁控制器選中的顏色

thePage.currentPageIndicatorTintColor = [UIColor redColor];

//添加到視圖

[self.view addSubview:thePage];

}

//實(shí)現(xiàn)分頁控制器與滾動(dòng)視圖的關(guān)聯(lián)

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

thePage.currentPage = theSceo.contentOffset.x/self.view.frame.size.width;

}

-(void)tz{

oneViewController *v1 = [oneViewController new];

[self presentViewController:v1 animated:YES completion:^{

}];

}

@end

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

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

  • 首先要封裝一個(gè)類,有了這個(gè)類,只要把類拖拽到你的工程,媽媽就再也不用擔(dān)心你不會(huì)做輪播圖了! 創(chuàng)建這個(gè)類如下: 類名...
    MangoJ閱讀 3,688評(píng)論 5 6
  • 輪播圖是App中常用的展示界面,主要用到的控件有UIScrollView和UIPageControl。難點(diǎn)有兩處,...
    爬樹的螞蟻閱讀 3,854評(píng)論 0 12
  • 提到app輪播圖,我們會(huì)想到好多種實(shí)現(xiàn)方法。這里我給大家介紹一下用三個(gè)UIImageView創(chuàng)建輪播圖的方法,這里...
    杯水救車薪閱讀 2,192評(píng)論 2 5
  • 我們無法改變?nèi)松钠瘘c(diǎn),但卻可以通過閱讀改變?nèi)松慕K點(diǎn)。我們無力改變?nèi)松拈L度,但卻可以通過閱讀改變?nèi)松膶挾群秃?..
    mydjohnson閱讀 1,749評(píng)論 0 49
  • ECMAScript 中的變量無特定的類型,定義變量時(shí)只用 var 運(yùn)算符,可以將它初始化為任意值。 可以隨時(shí)改變...
    json_jie閱讀 654評(píng)論 0 0

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