温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

QuiltView 瀑布流 (第三方)

发布时间:2020-07-08 20:30:48 来源:网络 阅读:321 作者:缘起愿落 栏目:开发技术


使用第三方 : 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 *p_w_picpaths;
@end


.m 文件

主要代码:

#define kNumberOfCells           50


- (void)dealloc {
    [_quiltView release];
    _quiltView = nil;
    
    [_p_w_picpaths release];
    _p_w_picpaths = 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 *)p_w_picpaths {
    if (!_p_w_picpaths) {
        NSMutableArray *p_w_picpathNames = [NSMutableArray array];
        for(int i = 0; i < kNumberOfCells; i++) {
            [p_w_picpathNames addObject:[NSString stringWithFormat:@"%d.jpeg", i % 10 + 1]];
        }
        _p_w_picpaths = [p_w_picpathNames retain];
    }
    return _p_w_picpaths;
}

- (UIImage *)p_w_picpathAtIndexPath:(NSIndexPath *)indexPath {
    return [UIImage p_w_picpathNamed:[self.p_w_picpaths objectAtIndex:indexPath.row]];
}

- (NSInteger)quiltViewNumberOfCells:(TMQuiltView *)TMQuiltView {
    return [self.p_w_picpaths count];
}

- (TMQuiltViewCell *)quiltView:(TMQuiltView *)quiltView cellAtIndexPath:(NSIndexPath *)indexPath {
    TMPhotoQuiltViewCell *cell = (TMPhotoQuiltViewCell *)[quiltView dequeueReusableCellWithReuseIdentifier:@"PhotoCell"];
    if (!cell) {
        cell = [[[TMPhotoQuiltViewCell alloc] initWithReuseIdentifier:@"PhotoCell"] autorelease];
    }
    
    cell.photoView.p_w_picpath = [self p_w_picpathAtIndexPath: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 p_w_picpathAtIndexPath:indexPath].size.height / [self quiltViewNumberOfColumns:quiltView];
}


附件:http://down.51cto.com/data/2364898
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI