QuiltView 瀑布流 (第三方)
使用第三方 : QuiltView (可在cocoapods上找到)
.h 文件
#import<UIKit/UIKit.h>#import"TMQuiltView.h"#import"TMPhotoQuiltViewCell.h"@interfaceSelfHomeViewController:UIViewController<TMQuiltViewDataSource,TMQuiltViewDelegate>{}@property(strong,nonatomic)TMQuiltView*quiltView;@property(strong,nonatomic)NSArray*p_w_picpaths;@end
.m 文件
主要代码:
#definekNumberOfCells50-(void)dealloc{[_quiltViewrelease];_quiltView=nil;[_p_w_picpathsrelease];_p_w_picpaths=nil;[superdealloc];}-(void)viewDidLoad{[superviewDidLoad];_quiltView=[[TMQuiltViewalloc]initWithFrame:self.view.bounds];_quiltView.dataSource=self;_quiltView.delegate=self;[self.viewaddSubview:_quiltView];[_quiltViewreloadData];}#pragmamark-QuiltViewControllerDataSource-(NSArray*)p_w_picpaths{if(!_p_w_picpaths){NSMutableArray*p_w_picpathNames=[NSMutableArrayarray];for(inti=0;i<kNumberOfCells;i++){[p_w_picpathNamesaddObject:[NSStringstringWithFormat:@"%d.jpeg",i%10+1]];}_p_w_picpaths=[p_w_picpathNamesretain];}return_p_w_picpaths;}-(UIImage*)p_w_picpathAtIndexPath:(NSIndexPath*)indexPath{return[UIImagep_w_picpathNamed:[self.p_w_picpathsobjectAtIndex:indexPath.row]];}-(NSInteger)quiltViewNumberOfCells:(TMQuiltView*)TMQuiltView{return[self.p_w_picpathscount];}-(TMQuiltViewCell*)quiltView:(TMQuiltView*)quiltViewcellAtIndexPath:(NSIndexPath*)indexPath{TMPhotoQuiltViewCell*cell=(TMPhotoQuiltViewCell*)[quiltViewdequeueReusableCellWithReuseIdentifier:@"PhotoCell"];if(!cell){cell=[[[TMPhotoQuiltViewCellalloc]initWithReuseIdentifier:@"PhotoCell"]autorelease];}cell.photoView.p_w_picpath=[selfp_w_picpathAtIndexPath:indexPath];cell.titleLabel.text=[NSStringstringWithFormat:@"%d",indexPath.row+1];returncell;}#pragmamark-TMQuiltViewDelegate-(NSInteger)quiltViewNumberOfColumns:(TMQuiltView*)quiltView{return3;}-(CGFloat)quiltView:(TMQuiltView*)quiltViewheightForCellAtIndexPath:(NSIndexPath*)indexPath{return[selfp_w_picpathAtIndexPath:indexPath].size.height/[selfquiltViewNumberOfColumns:quiltView];}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。