码迷,mamicode.com
首页 > 其他好文 > 详细

QuiltView 瀑布流 (第三方)

时间:2014-09-25 13:19:49      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:quiltview 瀑布流 (第三方)


使用第三方 : QuiltView  (可在cocoapods上找到)


.h 文件

#import <UIKit/UIKit.h>
#import "TMQuiltView.h"
#import "TMPhotoQuiltViewCell.h"


@interface SelfHomeViewController : UIViewController <TMQuiltViewDataSource,TMQuiltViewDelegate> {
}
@property(strong,nonatomic)TMQuiltView *quiltView;
@property(strong,nonatomic)NSArray *images;
@end


.m 文件

主要代码:

#define kNumberOfCells           50


- (void)dealloc {
    [_quiltView release];
    _quiltView = nil;
    
    [_images release];
    _images = nil;
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    _quiltView = [[TMQuiltView alloc] initWithFrame:self.view.bounds];
    _quiltView.dataSource = self;
    _quiltView.delegate = self;
    [self.view addSubview:_quiltView];
    
    [_quiltView reloadData];
}


#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 {
    return 3;
}

- (CGFloat)quiltView:(TMQuiltView *)quiltView heightForCellAtIndexPath:(NSIndexPath *)indexPath {
    return [self imageAtIndexPath:indexPath].size.height / [self quiltViewNumberOfColumns:quiltView];
}


QuiltView 瀑布流 (第三方)

标签:quiltview 瀑布流 (第三方)

原文地址:http://qccccc.blog.51cto.com/6004423/1558005

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!