iOS开发学习周报(七)

本文是iOS开发学习周报的第七期,主要探讨UICollectionView的基本使用,包括自定义布局和配置,以及UIImageView的基础操作和异步加载网络图片的方法。通过NSOperationQueue实现非阻塞UI的图片加载,解决了在UICollectionView中获取特定cell和selector传参的问题。
摘要由CSDN通过智能技术生成

iOS开发学习周报(七)

简介

课程名称 IOS开发实训 任课老师 郑贵锋老师&字节跳动工程师
学号 16340015 专业(方向) 软件工程(计应)
姓名 陈彬彬 Email 944131226@qq.com
开始日期 2019/04/27 完成日期 2019/05/02


本周记录

0.概括

  • UICollectionView基本使用
  • UIImageView基本使用
  • UIImageView异步加载网络图片

1.UICollectionView基本使用

参考:

iOS学习之UICollectionView

UILabel文字大小自适应之--SizeToFit

iOS 自定义UICollectionViewCell

iOS之流布局UICollectionView全系列教程

概括:

相比于 UITableviewUICollectionviewiOS6 之后引入的一个新的UI控件,它和 UITableview 有着许多的相似之处,但是它是一个比 UITableView 更加强大的一个视图控件,使用过程中需要实现数据源以及代理方法,其使用优点如下:

(1)系统自带的流水布局支持水平和垂直两种方式的布局;

(2)通过layout配置方式进行布局;

(3)collectionview中item的大小和位置可以自定义

(4)可以自定义一套layout的布局方案

关键代码:

  1. ViewController.m 添加 UICollectionView 并实现相关协议。
//
//  ViewController.m
//  week7-demo
//
//  Created by chenbb6 on 2019/5/11.
//  Copyright © 2019 chenbb6. All rights reserved.
//

#import "ViewController.h"
#import "CollectionViewCell.h"

@interface ViewController () <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property(nonatomic, strong) UICollectionView *collectionView;
@property(nonatomic, strong) NSString *identifier;

@end

@implementation ViewController

- (instancetype)init
{
   
    self = [super init];
    if (self) {
   
        [self initialize];
    }
    return self;
}

- (void)initialize {
   
    self.identifier = @"ReuseCell";
}

- (void)viewDidLoad {
   
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self loadSubView];
}

- (void)loadSubView{
   
    self.collectionView = ({
   
      	// 垂直布局
        UICollectionViewFlowLayout *fl = [[UICollectionViewFlowLayout alloc] init];
        fl.scrollDirection = UICollectionViewScrollDirectionVertical;
        UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:fl];
        [collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:self.identifier];
        [collectionView setBackgroundColor:[UIColor whiteColor]];
        collectionView.delegate = self;
        collectionView.dataSource = self;
        collectionView;
    });
    [self.view addSubview:self.collectionView];
}

# pragma mark -UICollectionViewDataSource

// cell样式设置
- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值