Latest 0.2.1
Homepage https://github.com/ac1217/KCBannerView
License MIT
Platforms ios 7.0, requires ARC
Dependencies SDWebImage
Authors

示例代码:

//
// ViewController.m
// 无线循环图片轮播器demo
//
// Created by xiliedu on 15/8/28.
// Copyright (c) 2015年 xiliedu. All rights reserved.
//

import "ViewController.h"

import "KCBannerView.h"

import "KCBanner.h"

@interface ViewController ()<KCBannerViewDelegate,KCBannerViewDataSource, UIScrollViewDelegate>

@property (nonatomic, strong) NSArray *banners;

@property (nonatomic, strong) KCBannerView *bannerView;

@property (nonatomic, strong) UIScrollView *sv;

@end

@implementation ViewController

  • (UIScrollView *)sv
    {
    if (!_sv) {
    _sv = [[UIScrollView alloc] init];
    _sv.delegate = self;
    }
    return _sv;
    }

  • (NSArray *)banners
    {
    if (!_banners) {

    KCBanner *banner0 = [[KCBanner alloc] init];
    banner0.url = [NSURL URLWithString:@"http://pic29.nipic.com/20130530/6434097_113007064309_2.jpg"];
    
    KCBanner *banner1 = [[KCBanner alloc] init];
    banner1.url = [NSURL URLWithString:@"http://pic50.nipic.com/file/20141010/19650248_153632125000_2.jpg"];
    banner1.title = @"sdfdsfsfsadfasdfasdfasdfsasfsdfds";

    //
    //
    KCBanner *banner2 = [[KCBanner alloc] init];
    banner2.url = [NSURL URLWithString:@"http://pic29.nipic.com/20130530/6434097_113007064309_2.jpg"];

    KCBanner *banner3 = [[KCBanner alloc] init];
    banner3.url = [NSURL URLWithString:@"http://pic50.nipic.com/file/20141010/19650248_153632125000_2.jpg"];
    banner3.title = @"sdfdsfsfsfssadfsafsafdfds";
    banner3.placeholderImage = [UIImage imageNamed:@"pic_default_icon"];
    
    _banners = @[banner0, banner1, banner2, banner3];

    // _banners = @[banner0];
    }

    return _banners;
    }

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup afte

    [self.view addSubview:self.sv];

    // 创建
    KCBannerView *bannerView = [[KCBannerView alloc] init];

    bannerView.backgroundImageView.image = [UIImage imageNamed:@"pic"];
    // 设置代理
    bannerView.delegate = self;
    // 数据源
    bannerView.dataSource = self;

// bannerView.pageControlPosition = KCBannerViewPageControlPositionRight;
bannerView.descPosition = KCBannerViewDescPositionBottom;
// 添加
[self.sv addSubview:bannerView];

self.bannerView = bannerView;

[bannerView setPageControlPageImage:[UIImage imageNamed:@"homepage_btn_like_off"]];
[bannerView setPageControlCurrentPageImage:[UIImage imageNamed:@"homepage_btn_like_on"]];

}

  • (void)touchesBegan:(NSSet<UITouch > )touches withEvent:(UIEvent *)event
    {

// [self.bannerView reloadData];
}

  • (void)viewDidLayoutSubviews
    {
    [super viewDidLayoutSubviews];

    self.sv.frame = self.view.bounds;

    self.bannerView.frame = CGRectMake(0, 0, self.view.frame.size.width, 150);

    self.sv.contentSize = CGSizeMake(0, 1000);
    }

pragma mark -KCBannerViewDelegate

  • (void)bannerView:(KCBannerView *)bannerView didSelectBannerAtIndex:(NSInteger)index
    {

// [bannerView reloadData];
}

pragma mark -KCBannerViewDatasource

  • (id )bannerView:(KCBannerView *)bannerView bannerForItemAtIndex:(NSInteger)index
    {

    return self.banners[index];
    }

  • (NSInteger)numberOfBannersInBannerView:(KCBannerView *)bannerView
    {

    return self.banners.count;
    }

  • (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
    {
    self.bannerView.repeat = NO;
    }

  • (void)scrollViewWillEndDragging:(UIScrollView )scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint )targetContentOffset
    {

    self.bannerView.repeat = YES;
    }

  • (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
    self.bannerView.contentOffset = scrollView.contentOffset;
    }

@end

Latest podspec

{
    "name": "KCBannerView",
    "version": "0.2.1",
    "summary": "u4e00u4e2au56feu7247u5faau73afu8f6eu64adu7684u6846u67b6",
    "description": "u56feu7247u65e0u7ebfu5faau73afu8f6eu64aduff0cu7b80u5355u6613u7528uff0cu8ddftableviewu7528u6cd5u4e00u6837uff0cu6027u80fdu597du3002",
    "homepage": "https://github.com/ac1217/KCBannerView",
    "license": "MIT",
    "authors": {
        "Erica": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/ac1217/KCBannerView.git",
        "tag": "0.2.1"
    },
    "source_files": "KCBannerView/**/*.{h,m}",
    "exclude_files": "Classes/Exclude",
    "requires_arc": true,
    "dependencies": {
        "SDWebImage": []
    }
}

Pin It on Pinterest

Share This