神奇女侠雷神3诸神黄昏百度网盘云

3250人阅读
iOS 布局(41)
给UICollectionView添加头视图
#import &PhotoWallCell.h&
#import &PhotoWallModel.h&
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
NSString *collectionCellIndentider =
@&collectionCellIndentider&;
@interface
ViewController () &UITextFieldDelegate,UICollectionViewDataSource,UICollectionViewDelegate&
@property (nonatomic ,weak)
UICollectionView& & & & *collectionV
@property (nonatomic,
strong) NSMutableArray& & & & *dataS
@property (nonatomic,
strong) NSMutableArray& & & & *section1;
@property (nonatomic,
strong) NSMutableArray& & & & *section2;
- (void)setupSomeParamars
& & _section1 = [NSMutableArray
& & _section2 = [NSMutableArray
for(int num =
0;num&5;num++){
& & & & PhotoWallModel *model = [[PhotoWallModel
& & & & model.photo = [UIImage
imageNamed:@&1.png&];
& & & & [_section1
addObject:model];
for(int num =
0;num&6;num++){
& & & & PhotoWallModel *model = [[PhotoWallModel
& & & & model.photo = [UIImage
imageNamed:@&1.png&];
& & & & [_section2
addObject:model];
& & _dataSource = [NSMutableArray
arrayWithObjects:_section1,_section2,
- (UICollectionView *)collectionView{
& & if (_collectionView) {
& & & & return
_collectionView;
CGFloat collectionViewHeight =
kScreenHeight - 190;
CGRect frame = CGRectMake(0,
150, kScreenWidth, collectionViewHeight);
& & UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout
layout.headerReferenceSize = CGSizeMake(320, 50);
UICollectionView *collectionView = [[UICollectionView
alloc] initWithFrame:frame
collectionViewLayout:layout];
& & collectionView.opaque =
& & collectionView.backgroundColor =
self.view.backgroundColor;
& & collectionView.dataSource =
& & collectionView.delegate =
& & collectionView.pagingEnabled =
& & collectionView.showsVerticalScrollIndicator =
& & collectionView.showsHorizontalScrollIndicator =
& & [self.view
addSubview:collectionView];
_collectionView = collectionV
&& & *& @brief&
& & [collectionView registerClass:[PhotoWallCell
class] forCellWithReuseIdentifier:collectionCellIndentider];
[collectionView registerClass:[PhotoWallCell class]& forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionCellIndentider];
return collectionV
#pragma mark -
#pragma mark -cell Delegate
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath
*)indexPath{
& & PhotoWallCell *cell = [collectionView
dequeueReusableCellWithReuseIdentifier:collectionCellIndentider
forIndexPath:indexPath];
& & cell.model =
self.dataSource[indexPath.section][indexPath.row];
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath
*)indexPath
& & PhotoWallModel *model = [[PhotoWallModel
& & model.photo = [UIImage
imageNamed:@&1&];
& & [_section1
addObject:model];
& & [self.collectionView
reloadData];
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [self.dataSource[section]
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
& & return
self.dataSource.count;
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath
*)indexPath{
& & UICollectionReusableView *reusableview =
& & if (kind == UICollectionElementKindSectionHeader){
& & & & UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionCellIndentider
forIndexPath:indexPath];
& & & & headerView.backgroundColor = [UIColor redColor];
& & & & reusableview = headerV
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:214565次
积分:3905
积分:3905
排名:第7677名
原创:150篇
转载:118篇
评论:29条
阅读:5050
(1)(3)(6)(10)(4)(3)(4)(7)(8)(6)(4)(8)(12)(21)(20)(6)(14)(7)(2)(13)(7)(11)(6)(21)(18)(33)(16)(5)IOS中集合视图UICollectionView中Decoration View的简易使用方法。
Decoration View是UICollectionView的装饰视图。苹果官方给的案例都没涉及到这个视图的使用。没有具体的细节。我今天用UICollectionView做了一个简易的书架。主要是Decoration View的使用方法。
效果如下:
基本的UICollectionView使用方法请自己查询。
#import "CVViewController.h"
#import "CVCell.h"
#import "CVLayout.h"
@interfaceCVViewController ()
@implementation CVViewController
- (void)viewDidLoad
[superviewDidLoad];
[self.coll registerClass:[CVCell class] forCellWithReuseIdentifier:@"cell"];
CVLayout *layout=[[CVLayout alloc] init];
[self.coll setCollectionViewLayout:layout];
- (void)didReceiveMemoryWarning
[superdidReceiveMemoryWarning];
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell"forIndexPath:indexPath];
其中CVCell是我自定义的一个
UICollectionViewCell
其中CVLayout是我自定义的一个
UICollectionViewLayout
接下来主要看一下自定义的layout
#import "CVLayout.h"
#import "CVDEView.h"
@implementation CVLayout
-(void)prepareLayout{
[super prepareLayout];
registerClass:[CVDEView
class] forDecorationViewOfKind:@"CDV"];//注册Decoration View
-(CGSize)collectionViewContentSize{
self.collectionView.frame.
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)path
UICollectionViewLayoutAttributes* attributes =
[UICollectionViewLayoutAttributeslayoutAttributesForCellWithIndexPath:path];
attributes.size = CGSizeMake(215/3.0, 303/3.0);
attributes.center=CGPointMake(80*(path.item+1), 62.5+125*path.section);
//Decoration View的布局。
- (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString*)decorationViewKind atIndexPath:(NSIndexPath *)indexPath{
UICollectionViewLayoutAttributes* att = [UICollectionViewLayoutAttributeslayoutAttributesForDecorationViewOfKind:decorationViewKind withIndexPath:indexPath];
att.frame=CGRectMake(0, (125*indexPath.section)/2.0, 320, 125);
att.zIndex=-1;
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{
NSMutableArray* attributes = [NSMutableArrayarray];
//把Decoration View的布局加入可见区域布局。
for (int y=0; y<3; y&#43;&#43;) {
NSIndexPath* indexPath = [NSIndexPathindexPathForItem:3inSection:y];
[attributes addObject:[selflayoutAttributesForDecorationViewOfKind:@"CDV"atIndexPath:indexPath]];
for (NSInteger i=0 ; i < 3; i&#43;&#43;) {
for (NSInteger t=0; t<3; t&#43;&#43;) {
NSIndexPath* indexPath = [NSIndexPathindexPathForItem:t inSection:i];
[attributes addObject:[selflayoutAttributesForItemAtIndexPath:indexPath]];
下面是最后的Decoration View的设计。
首先要继承
UICollectionReusableView
@implementation CVDEView
- (id)initWithFrame:(CGRect)frame
self = [superinitWithFrame:frame];
if (self) {
UIImageView *imageView=[[UIImageViewalloc] initWithFrame:frame];
imageView.image=[UIImageimageNamed:@"BookShelfCell.png"];
[selfaddSubview:imageView];
OK。就可以看到上面图上的效果了。

我要回帖

更多关于 正义联盟百度云盘资源 的文章

 

随机推荐