swift 快速创建一些基本控件
2024-08-28 18:53:37
1.tableview
private lazy var cellId = "cellId"
fileprivate lazy var tv : UITableView = {
let tv = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
tv.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
tv.translatesAutoresizingMaskIntoConstraints = false
tv.separatorStyle = .none
tv.backgroundColor = UIColor.white
tv.delegate = self
tv.dataSource = self
tv.bounces = false
return tv
}() // MARK: - UITableViewDelegate, UITableViewDataSource
extension JYJYRtbMineVc:UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
} func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) return cell
}
}
2.流水布局
let JYLoadImageCollectionCellId = "JYLoadImageCollectionCell"
let JYAddImageCollectionCellId = "JYAddImageCollectionCell"
private lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let itemWidth = CGFloat(Int((JY_DEVICE_WIDTH - 10 * 4)/3))
let itemHeight = itemWidth
layout.itemSize = CGSize(width: itemWidth, height: itemHeight)
layout.minimumLineSpacing = 0
layout.minimumInteritemSpacing = 0
layout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10) let collectionV = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
collectionV.translatesAutoresizingMaskIntoConstraints = false
// collectionV.register(UINib.init(nibName: "JYChooseShopTimeCollectionCell", bundle: nil), forCellWithReuseIdentifier: "JYChooseShopTimeCollectionCell")
collectionV.register(JYLoadImageCollectionCell.classForCoder(), forCellWithReuseIdentifier: JYLoadImageCollectionCellId)
collectionV.register(JYAddImageCollectionCell.classForCoder(), forCellWithReuseIdentifier: JYAddImageCollectionCellId)
collectionV.delegate = self
collectionV.dataSource = self
collectionV.backgroundColor = .white
collectionV.showsHorizontalScrollIndicator = false
collectionV.showsVerticalScrollIndicator = false return collectionV
}() extension JYShopDetailFigureVc:UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
} func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
} func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: JYAddImageCollectionCellId, for: indexPath) as! JYAddImageCollectionCell
return cell
} func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
}
}
最新文章
- JavaScript 基础回顾——数组
- php和syslog
- Docker Hub仓库注册,使用
- C# 对话框隐藏 标题栏
- NYOJ 106背包问题
- bash把所有屏幕输出重定向到文件并保持屏幕输出的方法
- hdu2571动态规划
- Winform动态加载TabControl用法
- git使用图解
- Redis系统学习 二、数据结构
- 【面向对象设计原则】之里氏替换原则(LSP)
- webpack的四个核心概念介绍
- 统计字符串中字符出现的次数(||和&;&;的区别)
- 不同组的id列表的汇总对比
- PAT 乙级 1091 N-自守数 (15 分)
- k-vim安装及The ycmd server SHUT DOWN (restart with ':YcmRestartServer')这种错误的解决方法
- Jquery 组 表单验证
- 尚硅谷springboot学习8-yaml基本语法
- Python框架级编程的能力要求
- 原!上线遇到的问题, java序列化关键字transient 修饰的属性变成null了
热门文章
- mybatisGenerator自动生成pojo、dao、xml文件
- shell命令中用source 和sh(或者bash)执行脚本的区别,以及export的作用
- debian下redis2.8.17安装过程
- 8张思维导图学习javascript
- OpenWrt上搭建纯L2TP服务器[ZT]
- ArcGIS案例学习笔记2_1_山顶点提取最大值提取
- .net上的 jpa
- fwrite()中参数含义——size和count经常用搞反
- 3DMAX 批量 场景 对象 导出 .X格式 脚本
- platform 系统是windows还是liunx