輪播引導(dǎo)頁

輪播引導(dǎo)頁


輪播引導(dǎo)頁早已成為主流的引導(dǎo)方式,下面加單介紹一下實(shí)現(xiàn)方式。


界面預(yù)覽:

GuidePages.gif

代碼簡(jiǎn)介:
主要知識(shí)點(diǎn):
UIScrollView 基礎(chǔ)控件的使用

    (instancetype)init
    {
return [self initWithImageDatas:nil completion:nil];
    }

    // init with imageDatas and completion     - (instancetype)initWithImageDatas:(NSArray *)imageDatas completion:(void (^)(void))buttonAction
    {
self = [super init];
if (self)
{
    [self initView];
    //因?yàn)槭褂昧藨屑虞d,_imageDatas = imageDatas不會(huì)調(diào)用initContentView
    [self setImageDatas:imageDatas];
    _buttonAction = buttonAction;
}
return self;
    }

    //懶加載,并初始化內(nèi)容- (void)setImageDatas:(NSArray *)imageDatas
    {
_imageDatas = imageDatas;
[self initContentView];
    }

    //基礎(chǔ)視圖初始化- (void)initView
    {
// init view
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

// init scrollView
_scrollView = [[UIScrollView alloc] init];
_scrollView.delegate = self;
_scrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
_scrollView.backgroundColor = [UIColor clearColor];
_scrollView.bounces = NO;
_scrollView.pagingEnabled = YES;
_scrollView.showsHorizontalScrollIndicator = NO;
[self addSubview:_scrollView];

// init pageControl
_pageControl =
    [[UIPageControl alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 30, SCREEN_WIDTH, 10)];
_pageControl.currentPage = 0;
_pageControl.hidesForSinglePage = YES;
_pageControl.pageIndicatorTintColor = [UIColor grayColor];
_pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
[self addSubview:_pageControl];

// init button
_actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
    }

    //指定數(shù)據(jù)后,初始化顯示內(nèi)容- (void)initContentView
   {
if (_imageDatas.count)
{
    _pageControl.numberOfPages = _imageDatas.count;
    _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * _imageDatas.count, SCREEN_HEIGHT);
    for (int i = 0; i < _imageDatas.count; i++)
    {
        NSString *imageName = _imageDatas[i];
        UIImageView *imgView =
            [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
        imgView.frame = CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        [self.scrollView addSubview:imgView];

        if (i == _imageDatas.count - 1)
        {
            _actionButton.frame =
                CGRectMake(SCREEN_WIDTH / 2 - 70, SCREEN_HEIGHT - 70, 140, 35);
            _actionButton.layer.cornerRadius = 5;
            _actionButton.layer.masksToBounds = YES;
            [_actionButton setTitle:@"進(jìn)  入" forState:UIControlStateNormal];
            _actionButton.tintColor = [UIColor whiteColor];
            _actionButton.backgroundColor = [UIColor redColor];
            [_actionButton addTarget:self
                              action:@selector(enterButtonClick)
                    forControlEvents:UIControlEventTouchUpInside];
            [imgView addSubview:_actionButton];
            //設(shè)置可以響應(yīng)交互,UIImageView的默認(rèn)值為NO
            imgView.userInteractionEnabled = YES;
        }
    }
}
   }- (void)enterButtonClick
   {
if (_buttonAction)
{
    _buttonAction();
}
   }- (void)scrollViewDidScroll:(UIScrollView *)scrollView
   {
_pageControl.currentPage = (_scrollView.contentOffset.x + SCREEN_WIDTH / 2) / SCREEN_WIDTH;
    }

下載地址:
http://pan.baidu.com/s/1c24pBwO

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

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

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,068評(píng)論 25 709
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,391評(píng)論 4 61
  • 出來近四年時(shí)間,每到假期回家都有一種日漸冷清的感覺。北方的冬天,樹上的葉子落得毛都不剩,村子后面海拔三十米的小山包...
    青杏兒閱讀 226評(píng)論 0 1
  • 六月的天,七月的雨,不只都是陰天和霉雨。 拖著疲憊的身子,趕了數(shù)千公里的火車。一路都是花生瓜子礦泉水,八寶粥碗面火...
    不將就生活閱讀 246評(píng)論 0 1
  • 王建軍 我是一名教師,一名語文教師,但從內(nèi)心中,我是懼怕這一稱謂的。在有些場(chǎng)合,當(dāng)陌生人問及我的職業(yè),我有些惶恐地...
    東營(yíng)王建軍閱讀 964評(píng)論 20 21

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