网格

//
// ViewController.m
// 222
//
// Created by 三哥哥 on 2018/11/1.
// Copyright © 2018年 三哥哥. All rights reserved.
//

#import “ViewController.h”

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>{
UITableView *tab;
}

@end
static NSString *coll=@“112”;
@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.barTintColor=[UIColor blackColor];
    self.navigationItem.title=@“数码科技”;
    self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:16]};
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@“➕” style:UIBarButtonItemStyleDone target:self action:@selector(rightButton)];
    tab=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    tab.delegate=self;
    tab.dataSource=self;

    [self.view addSubview:tab];
    }
    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
    }
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section0){
    return 2;
    }else{
    return 6;
    }
    }
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cc=@“11”;
    UITableViewCell *cell=[tab dequeueReusableCellWithIdentifier:cc];
    if(!cell){
    cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cc];
    }
    if(indexPath.section
    0){
    if(indexPath.row==0){
    tab.rowHeight=150;
    UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
    img.image=[UIImage imageNamed:@“京东头视图”];
    [cell addSubview:img];

      }else{
          tab.rowHeight=100;
          //初始化流水布局
          UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
          
          //设置格子的大小
          layout.itemSize = CGSizeMake(100, 100);
          
          //设置最小行间距
          layout.minimumLineSpacing = 1;
          
          //设置最小列间距
          layout.minimumInteritemSpacing = 1;
          //设置i网格
    

// layout.sectionInset=UIEdgeInsetsMake(10, 10, 10, 20);
//创建网格

        UICollectionView *colV = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100) collectionViewLayout:layout];
        
        colV.backgroundColor = [UIColor lightGrayColor];
        
        //设置数据源 代理
        colV.delegate = self;
        colV .dataSource = self;
        
        //停止滚动
        colV.scrollEnabled = NO;
        
        
        //注册网格
        [colV registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:coll];
        
        [cell addSubview:colV];

//
}
}else{

}

return cell;

}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 3;
}
//设置cell内容

  • (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    //重用
    UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:coll forIndexPath:indexPath];

    //设置cell内容
    UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 40, 40)];
    NSArray *arr1 = @[@“1.jpg”,@“3.jpg”,@“3.jpg”];
    //设置图片
    imgV.image = [UIImage imageNamed:arr1[indexPath.row]];
    //将图片添加到cell
    [cell addSubview:imgV];
    return cell;

}
-(void)rightButton{
NSLog(@“点击了!”);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值