关于UIScollectionView使用,字体打印,判断定位是否开启

@property (assign, nonatomic)int page;

@property (assign, nonatomic)int pageCount;

@property (strong, nonatomic) ScrollView *scrollView;

@end


@implementation MainViewController

// 构建广告滚动视图

- (void)createScrollView {

    self.scrollView = [[AdvertisingScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 175)];

    self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);


    self.scrollView.imageNameArray = [NSArray arrayWithObjects:@"picture1.png",@"picture2.png",@"picture3.png",@"picture4.png", nil];

    self.scrollView.PageControlShowStyle = UIPageControlShowStyleCenter;

    self.scrollView.pageControl.pageIndicatorTintColor = [UIColor whiteColor];

    self.scrollView.pageControl.currentPageIndicatorTintColor = [UIColor grayColor];

    [self.view addSubview:self.scrollView];

}

- (id)init

{

    self = [super init];

    if (self) {

        //[self setup];

    }

    return self;

}

//加载新数据

-(void)LoadNewMessage

{

}

//向上重新加载数据

-(void)UpReloadData

{//当页面小于总页数 就加入数据 否则等于原始数据

    [self.collectionView addHeaderWithCallback:^{

        if (self.page < self.pageCount) {

            self.page ++;

        } else {

            self.page = self.pageCount;

        }

        [self LoadNewMessage];

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

            // 结束刷新

            [self.collectionView headerEndRefreshing];

        });

    }];

}

//向下重新加载数据

-(void)DownReloadData

{

    [self.collectionView addFooterWithCallback:^{

        if (self.page < self.pageCount) {

            self.page    ++;

        } else {

            self.page = self.pageCount;

        }

        [self LoadNewMessage];

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

            // 结束刷新

            [self.collectionView footerEndRefreshing];

        });

    }];

}

- (void)dealloc

{

    NSLog(@"MJCollectionViewController--dealloc---");

}

- (void)viewDidLoad {

   /* x = 0;  // 打印所有字体名

    y= 0;

    NSArray *familyNames = [UIFont familyNames];

    for( NSString *familyName in familyNames ){

        x++;

       NSLog( @"===%d=Family: %s \n",x, [familyName UTF8String] );

        NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];

        for( NSString *fontName in fontNames ){

            y++;

           // printf( "-%d---\tFont: [[%s]] \n]", y,[fontName UTF8String] );

        }

    }*/

    // MicrosoftYaHei

    [super viewDidLoad]; 

    self.page = 0;

    self.pageCount = 0;

    [self createScrollView];

  

    selectedIdx = [NSMutableDictionary new];

    

//判断定位是否开启

    if ([CLLocationManager locationServicesEnabled] &&

        ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized

         || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)) {

       

            NSLog(@"定位功能以及开启");

        }

    else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied){

        NSLog(@"定位功能不可用,提示用户或忽略");

    }

    NavigationView *navigationView = [NavigationView new];

    [self.view addSubview:navigationView];

    int navigationHeight = navigationView.frame.size.height;

 

     self.navigationController.navigationBarHidden=YES;// 隐藏导航栏

    //[UIColor colorWithRed:0/152.0f green:122/148.0f blue:255/142.0f alpha:0.5];

    //self.view.backgroundColor = [UIColor whiteColor];

    

    //首页滚动推荐图

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

    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];

    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, navigationHeight,self.view.frame.size.width, self.view.frame.size.height - navigationHeight - 49) collectionViewLayout:flowLayout];

    flowLayout.headerReferenceSize = CGSizeMake(self.view.frame.size.width, 175);

    flowLayout.minimumInteritemSpacing = 0;

    //间距

    flowLayout.minimumLineSpacing = 4;

    flowLayout.sectionInset = UIEdgeInsetsMake(4, 4, 0, 4);

 

    self.automaticallyAdjustsScrollViewInsets = NO;//顶部不预留空白区域

    self.collectionView.delegate = self;

    self.collectionView.dataSource = self;

    

    [self.collectionView registerClass:[ProjectCollectionViewCell class] forCellWithReuseIdentifier:CellIdentifier];

    [self.collectionView setAllowsMultipleSelection:YES];

    [self.view addSubview:self.collectionView];

    [self.collectionView addSubview:self.scrollView];


    EntityInformation *entity = [EntityInformation new];

    aryInformation = [entity infomationCategoryArray];

    [self.collectionView reloadData];

  

    // 2.集成刷新控件

    [self UpReloadData];

    [self DownReloadData];

}


-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {

    return 1;

}

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

    return aryInformation.count;

}

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

    int cellWidth;

    int cellHight = (self.view.frame.size.width - 16)/3;

    switch (indexPath.row % 3) {

        case 0: case 1:

            cellWidth = (self.view.frame.size.width - 16)/3;

            break;

        case 2:

            cellWidth = (self.view.frame.size.width - 16)/3 + 1;

            break;

            default:

            break;

    }

    return CGSizeMake(cellWidth,cellHight);

}


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

    ProjectCollectionViewCell *cell=(ProjectCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];//@"cellEmpty"

    cell.row = indexPath.row % 3;

    

    [cell setInformationCell:aryInformation[indexPath.row]];

    return cell;

}

//选中

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

    

    [selectedIdx setValue:@"1" forKey:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];


    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    BOOL switchOn =[defaults boolForKey:@"switchOn"];

    if (!switchOn) {

        InformationClassificationViewController *icvc=[InformationClassificationViewController new];

        [self presentViewController:icvc animated:YES completion:nil];

    } else {

        SecondViewController *svc = [SecondViewController new];

        [self presentViewController:svc animated:YES completion:nil];

    }

}

//取消选择

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {

    [selectedIdx removeObjectForKey:[NSString stringWithFormat:@"%ld", (long)indexPath.row]];

}

-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    return YES;

}


- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath

{

    return YES;

}

- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath {

    

}


- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath {

    

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值