91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

CollectionView純代碼手敲

發布時間:2020-07-21 22:53:25 來源:網絡 閱讀:412 作者:bhbh110 欄目:開發技術

一、定義我們的CollectViewCell

//  Tiny_CollectionViewCell.h

//  Tiny_UICollectionViewController

//

//  Created by Tiny on 15-6-16.

//  Copyright (c) 2015 Tiny. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface Tiny_CollectionViewCell : UICollectionViewCell


@property(strong, nonatomic) UIImageView *p_w_picpathView; //圖片定義

@property(strong, nonatomic) UILabel *label; //標簽定義


@end



二、實現我們的CollectViewCell:


//

//  Tiny_CollectionViewCell.m

//  Tiny_UICollectionViewController

//

//  Created by Tiny on 15-6-16.

//  Copyright (c) 2015 Tiny. All rights reserved.

//


#import "Tiny_CollectionViewCell.h"


@implementation Tiny_CollectionViewCell

@synthesize p_w_picpathView;

@synthesize label;



- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self)

    {

        //初始化圖片

        self.p_w_picpathView = [[UIImageView alloc] init];

        //定義圖片frame

        [self.p_w_picpathView setFrame:CGRectMake(25, 15, 101, 101)];

        [self.contentView addSubview:self.p_w_picpathView];

        

        //初始化標簽

        self.label = [[UILabel alloc] init];

        //定義標簽frame

        [self.label setFrame:CGRectMake(35, 121, 150, 20)];

        [self.contentView addSubview:self.label];

    }

    return self;

}

@end



三、定義我們的控制器ViewController:


//

//  Tiny_ViewController.h

//  Tiny_UICollectionViewController

//

//  Created by Tiny on 15-6-16.

//  Copyright (c) 2015 Tiny. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface Tiny_ViewController : UIViewController<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>


@property(strong, nonatomic) NSArray *events;

@property(strong, nonatomic) UICollectionView *collectionView;


@end



四、實現我們的控制器ViewController:

//

//  Tiny_ViewController.m

//  Tiny_UICollectionViewController

//

//  Created by Tiny on 15-6-16.

//  Copyright (c) 2015 Tiny. All rights reserved.

//


#import "Tiny_ViewController.h"

#import "Tiny_CollectionViewCell.h"


@interface Tiny_ViewController ()


@end


@implementation Tiny_ViewController


- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.


    CGRect screenRect = [[UIScreen mainScreen] bounds];

    

    NSBundle *bundle = [NSBundle mainBundle];

    NSString *plistPath = [bundle pathForResource:@"events" ofType:@"plist"];

    

    //獲取屬性列表文件中的全部數據

    NSArray *array = [[NSArray alloc] initWithContentsOfFile:plistPath];

    self.events = array;

    

    UICollectionViewFlowLayout *layout= [[UICollectionViewFlowLayout alloc]init];

    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, screenRect.size.width, screenRect.size.height) collectionViewLayout:layout];

    [self.collectionView registerClass:[Tiny_CollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];

    self.collectionView.delegate = self;

    self.collectionView.dataSource = self;

    [self.collectionView setBackgroundColor:[UIColor clearColor]];

    

    [self.view addSubview:self.collectionView];

}


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

{

    return [self.events count] / 2;

}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{

    return 2;

}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{

    Tiny_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

    NSDictionary *event = [self.events objectAtIndex:(indexPath.section * 2 + indexPath.row)];

    cell.p_w_picpathView.p_w_picpath = [UIImage p_w_picpathNamed:[event objectForKey:@"p_w_picpath"]];

    cell.label.text = [event objectForKey:@"name"];


    return cell;

}


#pragma mark - UICollectionViewDelegate

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

{

    NSDictionary *event = [self.events objectAtIndex:(indexPath.section*2 + indexPath.row)];

    

    UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"選擇項目" message:[NSString stringWithFormat:@"你選了%@項目", [event objectForKey:@"name"]] delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];

    [a show];

}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath

{

    return CGSizeMake(140, 140);

}



- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end



五、導入events.plist文件(內容大概如下)

    CollectionView純代碼手敲

    


六、完美運行

    

    CollectionView純代碼手敲

    


七、 資源參考 關老師寫的iOS開發指南 !





向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

江西省| 涟水县| 镇平县| 迁西县| 若尔盖县| 花莲县| 陆丰市| 平泉县| 磴口县| 临安市| 铁力市| 北辰区| 尼勒克县| 化州市| 扶余县| 军事| 百色市| 南皮县| 洪湖市| 阜康市| 金坛市| 定襄县| 永川市| 游戏| 棋牌| 彰武县| 璧山县| 湘乡市| 德保县| 区。| 哈密市| 花莲县| 桓仁| 防城港市| 乌兰察布市| 军事| 什邡市| 定州市| 五家渠市| 宣化县| 富民县|