我们为我们的 Shoebox 应用 开发了一个 quilt view
以下是从示例视图控制器中摘录的内容,展示了如何轻松设置 TMQuiltView。您也可以直接在 XCode 中打开 TMQuiltViewDemo 并构建项目。
@interface TMDemoQuiltViewController ()
@property (nonatomic, retain) NSArray *images;
@end
@implementation TMDemoQuiltViewController
@synthesize images = _images;
- (void)dealloc {
[_images release], _images = nil;
[super dealloc];
}
#pragma mark - UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.quiltView.backgroundColor = [UIColor blackColor];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
#pragma mark - QuiltViewControllerDataSource
- (NSArray *)images {
if (!_images) {
NSMutableArray *imageNames = [NSMutableArray array];
for(int i = 0; i < kNumberOfCells; i++) {
[imageNames addObject:[NSString stringWithFormat:@"%d.jpeg", i % 10 + 1]];
}
_images = [imageNames retain];
}
return _images;
}
- (UIImage *)imageAtIndexPath:(NSIndexPath *)indexPath {
return [UIImage imageNamed:[self.images objectAtIndex:indexPath.row]];
}
- (NSInteger)quiltViewNumberOfCells:(TMQuiltView *)TMQuiltView {
return [self.images count];
}
- (TMQuiltViewCell *)quiltView:(TMQuiltView *)quiltView cellAtIndexPath:(NSIndexPath *)indexPath {
TMPhotoQuiltViewCell *cell = (TMPhotoQuiltViewCell *)[quiltView dequeueReusableCellWithReuseIdentifier:@"PhotoCell"];
if (!cell) {
cell = [[[TMPhotoQuiltViewCell alloc] initWithReuseIdentifier:@"PhotoCell"] autorelease];
}
cell.photoView.image = [self imageAtIndexPath:indexPath];
cell.titleLabel.text = [NSString stringWithFormat:@"%d", indexPath.row + 1];
return cell;
}
#pragma mark - TMQuiltViewDelegate
- (NSInteger)quiltViewNumberOfColumns:(TMQuiltView *)quiltView {
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft
|| [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) {
return 3;
} else {
return 2;
}
}
- (CGFloat)quiltView:(TMQuiltView *)quiltView heightForCellAtIndexPath:(NSIndexPath *)indexPath {
return [self imageAtIndexPath:indexPath].size.height / [self quiltViewNumberOfColumns:quiltView];
}
@end
TMQuiltView
版权所有 (c) 2012 1000memories
以下是对任何获取此软件及其相关文档文件(“软件”)副本的个人或实体的许可,免费许可此类软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许向软件提供副本的个人因此进行操作,前提是遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或实质部分中。
软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于对适销性、适用于特定目的和不受侵犯的保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论这类索赔、损害或其他责任是基于合同、侵权或其他方式产生,并且这些是基于、来自或与软件或使用或以其他方式使用软件相关。
请随时联系我们的 [email protected]。