这次Demo是关于UICollectionView的
//
// ViewController.swift
// UIKitPrograming
//
import UIKit
class ViewController: UIViewController {
// 定义一些不变量
let ScreenWidth = UIScreen.main.bounds.width // 屏幕宽度的一半
let cellIdentifier = "cell"
let headerIdentifier = "header"
let footerIdentifier = "footer"
let headerKind = UICollectionView.elementKindSectionHeader
let footerKind = UICollectionView.elementKindSectionFooter
// 返回一个随机的颜色
func randomColor() -> UIColor {
return UIColor(displayP3Red: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// 先设置布局,这是collectionView必须做的
let layout = UICollectionViewFlowLayout()
layout.