GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - chenddcoder/MLInfiniteScrollView: 实现无限自动滚动的轮播图 ScrollView, 可以通过继承 MLInfiniteScrollViewCell 来实现自定义 Cell 的展示.

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

13 Commits
13 Commits

Folders and files

NameName
Last commit message
Last commit date
MLInfiniteScrollViewDemo
MLInfiniteScrollViewDemo
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

MLInfiniteScrollView

实现无限自动滚动的轮播图 ScrollView, 可以通过继承 MLInfiniteScrollViewCell 来实现自定义 Cell 的展示.

例子: UIViewController 中添加一个 MLInfiniteScrollView

  1. 声明一个 MLInfiniteScrollView成员变量(我推荐您这么做, 因为您需要在 ViewWillDisAppear 方法中调用 MLInfiniteScrollView 实例的 startAutoScroll 方法来停止滚动, 否则由于定时器的存在, 将会无法释放.) 和 NSMutableArray数据源数组.

@property (nonatomic, strong) MLInfiniteScrollView *scrollView;

@property (nonatomic, strong) NSMutableArray *dataSource;

  1. 初始化您的数据源数组, 在这里我们给数据源数组添加 UIColor 实例.

    self.dataSource = [[NSMutableArray alloc] initWithObjects:@{@"color":[UIColor redColor], @"title":@"红色"}, @{@"color":[UIColor orangeColor], @"title":@"橙色"}, @{@"color":[UIColor yellowColor], @"title":@"黄色"}, @{@"color":[UIColor greenColor], @"title":@"绿色"}, @{@"color":[UIColor cyanColor], @"title":@"青色"}, @{@"color":[UIColor blueColor], @"title":@"蓝色"}, @{@"color":[UIColor purpleColor], @"title":@"紫色"}, @{@"color":[UIColor brownColor], @"title":@"棕色"}, nil];

  2. 初始化 MLInfiniteScrollView, 您只需要调用这一个工厂方法, 便可以轻松实例化一个 MLInfiniteScrollView 实例.

self.scrollView = [MLInfiniteScrollView infiniteScrollViewWithFrame: CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 200) delegate:self dataSource:self timeInterval:4.0 inView: self.view];

  1. 实现 MLInfiniteScrollView 的数据源方法

(NSInteger) numberOfItemsInInfiniteScrollView:(MLInfiniteScrollView *)scrollView

{

  return self.dataSource.count;
  
}

(MLInfiniteScrollViewCell *) infiniteScrollView:(MLInfiniteScrollView *)scrollView viewAtIndex:(NSInteger)index

{

    MLInfiniteScrollViewCell *cell = [scrollView dequeueReusableCellWithIdentifier: @"CellIdentifier"];

    if (!cell) {
        cell = [MLInfiniteScrollViewCell infiniteScrollViewCellWithStyle: MLInfiniteScrollViewStyleSubTitle     reusableIdentifier: @"CellIdentifier" bounds: scrollView.bounds];
    }

   cell.contentView.backgroundColor = [self.dataSource[index] objectForKey:@"color"];

   if (index%2) {
      cell.textLabel.text = [self.dataSource[index] objectForKey: @"title"];
    } else {
      cell.imageView.image = [UIImage imageNamed:@"data18.bin_1"];
    }

  return cell;

}

  1. 请在 ViewController 的 ViewWillAppear 中加入以下代码

    (void) viewWillAppear:(BOOL)animated

     {
    
        [super viewWillAppear: animated];
    
        [self.scrollView startAutoScroll];
    
     }
    
  2. 请在 ViewController 的 ViewWillDisappear 中加入以下代码

    (void) viewWillDisappear:(BOOL)animated

     {
    
          [super viewWillDisappear: animated];
    
          [self.scrollView stopAutoScroll];
    
     }
    
  3. 简单的几步, 就已经实现了一个轮播图的效果. 当然您还可以继承 MLInfiniteScrollViewCell 类来实现自定义的 Cell, 更多详情请参照 MLInfiniteScrollViewDemo.

  4. 如果您有什么疑问或建议, 您可以随时联系我, 尽管放马过来吧大神们. 邮箱: [email protected] QQ: 2042169059

About

实现无限自动滚动的轮播图 ScrollView, 可以通过继承 MLInfiniteScrollViewCell 来实现自定义 Cell 的展示.

Resources

Readme
GPL-2.0 license
Activity

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.