GithubHelp home page GithubHelp logo

ikhsan / iainfinitegridview Goto Github PK

View Code? Open in Web Editor NEW
147.0 24.0 41.0 136 KB

[Deprecated] Infinite grid view with UITableView-esque data source methods

License: Other

Ruby 5.23% Objective-C 94.77%

iainfinitegridview's Introduction

#IAInfiniteGridView

image image

##Infinite grid view with UITableView-esque data source methods

If you want to have an infinite scroll view with our own grids, just drag IAInfiniteGridView, set and implement its data source, and your good to go!

##Features

  • Circular mode
  • Custom set paging enabled
  • Familiar data source method to implement
  • Using reuse queue for better performance
  • Also, delegate method to accept did select grid

##How To

  • Drag the IAInfiniteGridView to your project
  • Add the class via code or in Interface Builder
  • Set your view controller to conform IAInfiniteGridDataSource
  • Set its data source via code ``` infiniteGridView.dataSource = self
or via IB by ctrl+drag it to your view controller and add as its `dataSource`

* Implement the required data source methods

``` objective-c
- (UIView *)infiniteGridView:(IAInfiniteGridView *)gridView forIndex:(NSInteger)gridIndex {
    UIView *grid = [self.gridView dequeueReusableGrid];
	
	CGFloat gridWidth = [self infiniteGridView:gridView widthForIndex:gridIndex];
	CGRect frame = CGRectMake(0.0, 0.0, gridWidth, gridView.bounds.size.height);
	
	UILabel *numberLabel;
    if (grid == nil) {
		grid = [[UIView alloc] initWithFrame:frame];
        
        numberLabel = [[UILabel alloc] initWithFrame:frame];
        [numberLabel setBackgroundColor:[UIColor clearColor]];
        [numberLabel setTextColor:[UIColor whiteColor]];
		[numberLabel setFont:[UIFont boldSystemFontOfSize:(gridView.bounds.size.height * .4)]];
        [numberLabel setTextAlignment:NSTextAlignmentCenter];
        [numberLabel setTag:kNumberLabelTag];
        [grid addSubview:numberLabel];
    } else {
		grid.frame = frame;
		numberLabel = (UILabel *)[grid viewWithTag:kNumberLabelTag];
		numberLabel.frame = frame;
	}
    
    // set properties    
    NSInteger mods = gridIndex % [self numberOfGridsInInfiniteGridView:gridView];
    if (mods < 0) mods += [self numberOfGridsInInfiniteGridView:gridView];
    CGFloat red = mods * (1 / (CGFloat)[self numberOfGridsInInfiniteGridView:gridView]);
    grid.backgroundColor = [UIColor colorWithRed:red green:0.0 blue:0.0 alpha:1.0];
    
    // set text
    [numberLabel setText:[NSString stringWithFormat:@"[%d]", gridIndex]];
    
    return grid;
}

// this method is used for circular mode, not very useful for infinite mode
- (NSUInteger)numberOfInfiniteGrids {
    return 10;
}

- (CGSize)infiniteGridSize {    
    return CGSizeMake(150.0, 150.0);
}
  • Scroll the heck out of it!

For more clarity, please review the code in the sample project Infinite.

##To Do

  • Horizontal scrolling
  • Custom paging improvements
  • Custom identifier

Dependencies

[iOS 5.0+] - Build with iOS 5 with ARC enabled

##License

IAInfiniteGridView is available under the MIT License.

Copyright (c) 2013 Ikhsan Assaat

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Credits

IAInfiniteGridView was created by Ikhsan Assaat

Feel free to contact me,

iainfinitegridview's People

Contributors

ikhsan avatar pbernery avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iainfinitegridview's Issues

Memory usage.

First of all, thank you for the great component, I have small tip about improving memory usage for the infinite grid.

I noticed huge memory usage while profiling an app. using the infinite grid view.
When you scroll the infinite grid, method

tileGridsFromMinX:toMaxX:

which adds/removes views from one side using either

 [lastGrid removeFromSuperview] or [firstGrid removeFromSuperview] 

in ARC env. [lastGrid removeFromSuperview] doesn't release the view.

Similar problem I encountered with CorePlot: https://groups.google.com/forum/#!searchin/coreplot-discuss/memory/coreplot-discuss/nWui9VjnMtQ/er2FO3o9syYJ

If you do:

lastGrid = [self.visibleGrids lastObject];
while (lastGrid.frame.origin.x > maximumVisibleX) {
   [lastGrid removeFromSuperview];
   [self.visibleGrids removeLastObject];
   [self.gridReusableQueue addObject:lastGrid];

   lastGrid = nil;

   lastGrid = [self.visibleGrids lastObject];
}

Memory usage is much more efficient. I've tested it in instruments, without lastGrid = nil I can easily reach 60Mb after 30 seconds of scrolling, with the line it increases but very slowly stays around 15Mb.

scrollViewDidScroll method lost

Hello. I use your library and can't use standart scrollview.delegate method.

  • (void)scrollViewDidScroll:(UIScrollView *)scrollView{}

When i add infinitescrollview delegate to self^ pagination did.t work.

Disable Infinity

How can i use IAInfiniteGridView like a simple ScrollView without circular and infinit?

Adding Programmatically

I cannot figure out how to setup and add a IAInfiniteGridView programmatically. Am I doing anything wrong?

IAInfiniteGridView *gridView = [[IAInfiniteGridView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 568.0f)];
    gridView.paging = YES;

    gridView.hidden = NO;
    gridView.dataSource = self;
    gridView.gridDelegate = self;

    self.gridView = gridView;

    [self.view addSubview:self.gridView];

Setting it up for UIViews only? (It "refreshes" the view back to it's default view)

Hey!

Could you please guide me into setting it up with pre-determined UIView's only? I have 8 gridViews and for each one, I programmatically added code to set up the view with Images and Labels. It works fine for the first gridView, but as I scroll, all the other views I created disappeared, and when I try to scroll back to the first view, that one disappears as well. Any help with this would be much appreciated!

Here's some of my code:

  • (UIView *)infiniteGridView:(IAInfiniteGridView *)gridView forIndex:(NSInteger)gridIndex {
    UIView *grid = [self.gridView dequeueReusableGrid];
    CGRect frame = CGRectMake(0.0, 0.0, [self infiniteGridSize].width, [self infiniteGridSize].height);
    CGRect imageframe = CGRectMake(-2, -7, 105, 105);
    CGRect labelframe = CGRectMake(100, 47, 160, 40);
    CGRect labelTframe = CGRectMake(39, 82, 50, 40);
    CGRect windframe = CGRectMake(260, 50, 30, 30);
    CGRect timeFrame = CGRectMake(160, 10, 70, 30);
    CGRect windLframe = CGRectMake(292, 53, 60, 30);
    if (gridIndex == 0) {
    grid = [[UIView alloc] initWithFrame:frame];
    BGView = [[UIImageView alloc] initWithFrame:frame];
    BGView.contentMode = UIViewContentModeScaleAspectFill;
    conditionsImageView = [[UIImageView alloc] initWithFrame:imageframe];
    conditionsImageView.contentMode = UIViewContentModeScaleAspectFit;
    wind1 = [[UIImageView alloc] initWithFrame:windframe];
    wind1.contentMode = UIViewContentModeScaleAspectFit;
    wind1.image = [UIImage imageNamed:@"WindT.png"];
    labelW = [[UILabel alloc] initWithFrame:windLframe];
    timeLabel1 = [[UILabel alloc] initWithFrame:timeFrame];
    label = [[UILabel alloc] initWithFrame:labelframe];
    labelT = [[UILabel alloc] initWithFrame:labelTframe];
    labelT.backgroundColor = [UIColor clearColor];
    labelW.backgroundColor = [UIColor clearColor];
    label.backgroundColor = [UIColor clearColor];
    timeLabel1.backgroundColor = [UIColor clearColor];
    label.font = [UIFont fontWithName:@"League Gothic" size:27];
    labelT.font = [UIFont fontWithName:@"League Gothic" size:30];
    timeLabel1.font = [UIFont fontWithName:@"League Gothic" size:25];
    labelW.font = [UIFont fontWithName:@"League Gothic" size:23];
    [label setTextColor:[UIColor whiteColor]];
    [timeLabel1 setTextColor:[UIColor whiteColor]];
    [labelT setTextColor:[UIColor whiteColor]];
    [labelW setTextColor:[UIColor whiteColor]];
    [grid addSubview:BGView];
    [grid addSubview:label];
    [grid addSubview:wind1];
    [grid addSubview:labelW];
    [grid addSubview:labelT];
    [grid addSubview:timeLabel1];
    [grid addSubview:conditionsImageView];
    }
    if (gridIndex == 1) {
    grid = [[UIView alloc] initWithFrame:frame];
    BGView2 = [[UIImageView alloc] initWithFrame:frame];
    BGView2.contentMode = UIViewContentModeScaleAspectFill;
    conditionsImageView2 = [[UIImageView alloc] initWithFrame:imageframe];
    conditionsImageView2.contentMode = UIViewContentModeScaleAspectFit;
    wind2 = [[UIImageView alloc] initWithFrame:windframe];
    wind2.contentMode = UIViewContentModeScaleAspectFit;
    wind2.image = [UIImage imageNamed:@"WindT.png"];
    label2W = [[UILabel alloc] initWithFrame:windLframe];
    timeLabel2 = [[UILabel alloc] initWithFrame:timeFrame];
    label2 = [[UILabel alloc] initWithFrame:labelframe];
    label2T = [[UILabel alloc] initWithFrame:labelTframe];
    label2T.backgroundColor = [UIColor clearColor];
    label2W.backgroundColor = [UIColor clearColor];
    label2.backgroundColor = [UIColor clearColor];
    timeLabel2.backgroundColor = [UIColor clearColor];
    label2.font = [UIFont fontWithName:@"League Gothic" size:27];
    label2T.font = [UIFont fontWithName:@"League Gothic" size:30];
    timeLabel2.font = [UIFont fontWithName:@"League Gothic" size:25];
    label2W.font = [UIFont fontWithName:@"League Gothic" size:23];
    [label2 setTextColor:[UIColor whiteColor]];
    [timeLabel2 setTextColor:[UIColor whiteColor]];
    [label2T setTextColor:[UIColor whiteColor]];
    [label2W setTextColor:[UIColor whiteColor]];
    [grid addSubview:BGView2];
    [grid addSubview:label2];
    [grid addSubview:wind2];
    [grid addSubview:label2W];
    [grid addSubview:label2T];
    [grid addSubview:timeLabel2];
    [grid addSubview:conditionsImageView2];
    }

    NSInteger mods = gridIndex % [self numberOfInfiniteGrids];
    if (mods < 0) mods += [self numberOfInfiniteGrids];
    CGFloat red = mods * (1 / (CGFloat)[self numberOfInfiniteGrids]);

    grid.backgroundColor = [UIColor colorWithRed:red green:0.0 blue:0.0 alpha:1.0];

    return grid;
    }

  • (NSUInteger)numberOfInfiniteGrids {
    return 2;
    }

  • (CGSize)infiniteGridSize {
    return CGSizeMake(320, 120);
    }

Thanks!

Crash on subview count is 0.

When we set number of count to 0 it will crash on below code.

[self.dataSource numberOfGridsInInfiniteGridView:self] showing garbage value and app crash.

Can any one have solutions?

Thanks,
Dhaval

Setting Paging & Circular Programatically

I implemented this control line for line and it worked fine with paging and circular turned off. Then I tried to add this:

- (void)viewDidAppear:(BOOL)animated
{
    [self.gridView setCircular:YES];
    [self.gridView setPagingEnabled:YES];
    [self.gridView jumpToIndex:0];
}

With some very strange results. The paging would work for the first scroll through but after that would gradually offset itself - more and more.

So I don't know what the issue is there, but a workaround is to add/change the initialization method in IAInfiniteGridView.m

- (void)initialization {
    ...
    self.circular = YES;
    self.paging = YES;
    ...
}

Maybe someone can shed some light onto what's going on.

Wrong pageIndex number when scrolling backwards

The pageIndex number in
(void)infiniteGridView:(IAInfiniteGridView *)gridView didScrollToPage:(NSInteger)pageIndex
logs in decrementing number but sometimes the pageIndex logs in non succeeding number then continues to decrement again. Especially when circular is enabled.
No problem in incrementing pageIndex.

Btw, nice control. :D

Reload Views

Is there any methot to reload views . Like [tableView reloadData];

3 views total-centered

I was wondering if it was possible to have 3 total views, and to have the current one centered in the view like in this image below:

ios simulator screen shot jul 16 2015 1 09 35 pm

How would I be able to achieve this? I do not want all 3 views to be fully on screen. I just want the selected view to be centered and on screen, with the remaining 2 half-visible on the side.

content size (5x views size)

Why is scrollview content size 5 times bigger compared to the number of elements part of the scrolling view ?

self.contentSize = CGSizeMake(5 * totalGrids * gridSize.width, gridSize.height);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.