如果您想要具有我们自己的网格的无尽滚动视图,只需将 IAInfiniteGridView 拖放到项目中,设置并实现其数据源即可!
IAInfiniteGridView
拖放到您的项目中IAInfiniteGridDataSource
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);
}
为了更加清晰,请参阅示例项目中 Infinite
的代码。
[iOS 5.0+] - 使用禁用 ARC 的 iOS 5 构建
IAInfiniteGridView 可在 MIT 许可协议下使用。
版权所有 (c) 2013 Ikhsan Assaat
兹特此授予任何人免费获取本软件及其相关文档文件(以下简称“软件”)的副本的权利,包括但不仅限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本,并允许接收软件的人进行此类操作,但前提是
上述版权声明和本许可声明应包含在所有副本或软件的实质性部分中。
软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于对适销性、适用于特定目的和不受侵权的保证。在任何情况下,作者或版权所有者均不应对任何索赔、损害或其他责任承担任何责任,无论该索赔、损害或其他责任是基于合同、侵权或其他方式,源于、因或与软件的使用或任何其他方式使用有关。
IAInfiniteGridView 由 Ikhsan Assaat 创建。
请随时联系我: