swift 快速创建一些基本控件
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) {
}
}
swift 快速创建一些基本控件的更多相关文章
- 用swift创建各种UI控件【iSwifting社区】
为了方便大家学习,www.iSwifting.com社区为大家准备了创建各种UI控件的代码.開始看着语法可能有些别扭,当用习惯了,就认为还是非常不错的. 社区还添加了问答专区.有问题的朋友.虽然问.大 ...
- 【WPF学习】第六十五章 创建无外观控件
用户控件的目标是提供增补控件模板的设计表面,提供一种定义控件的快速方法,代价是失去了将来的灵活性.如果喜欢用户控件的功能,但需要修改使其可视化外观,使用这种方法就有问题了.例如,设想希望使用相同的颜色 ...
- 使用前端开发工具包WijmoJS - 创建自定义DropDownTree控件(包含源代码)
概述 最近,有客户向我们请求开发一个前端下拉控件,需求是显示了一个列表,其中包含可由用户单独选择的项目控件,该控件将在下拉列表中显示多选TreeView(树形图). 如今WijmoJS已经实现了该控件 ...
- 创建 WPF 工具箱控件
创建 WPF 工具箱控件 WPF (Windows Presentation Framework) 工具箱控件模板允许您创建 WPF 控件,会自动添加到 工具箱 安装扩展的安装. 本主题演示如何使用模 ...
- 通过WinForm控件创建的WPF控件无法输入的问题
今天把写的一个WPF程序发布到别的机器上执行,发现一个比较奇怪的问题:在那个机器上用英文输入法无法输入数字,非要切换到中文输入法才行:但在我的机器上却是好好的. 最开始以为是输入法的问题,弄了好一阵子 ...
- android学习七(创建自己定义控件)
前面学习的是android的基本控件和布局的使用,可是主要的控件和布局有时候并不能实现复杂的布局.我们来看下各种控件和布局的关系. 可见全部的控件都是直接或者间接的继承自View的,全部的布局都是直接 ...
- 关于如何在 Unity 的 UI 菜单中默认创建出的控件 Raycast Target 属性默认为 false
关于如何在 Unity 的 UI 菜单中默认创建出的控件 Raycast Target 属性默认为 false 我们在 Unity 中通过 UI 菜单创建的各种控件,比如 Text, Image 等, ...
- React 创建自己定义控件
React是Facebook的内部项目,当时facebook对自己市面上全部的javascript MVC都不惬意,于是就自己创建了一个新的框架.发现还挺好用.于是就开源了,这就是React. Rea ...
- IOS入门之创建视图和控件绑定
学习IOS几天了,跟着教程做了两个小应用了,现在先来总结一下.今天就是创建视图和绑带到代码了.其实就是常见的MVC模式实现. 使用的Xcode版本是8.2. 在Xcode创建项目之后,默认就会创建一个 ...
随机推荐
- 配置maven访问nexus,配置项目pom.xml以发布maven项目到nexus中
maven访问nexus有三种配置方法,分别为: 项目pom.xml,优先级最高: user的settings.xml,优先级中,未在pom.xml中配置repository标签,则使用这个配置: m ...
- java web项目使用IDEA打成war包
步骤: 1.点击 File -->Project Structure...如下图: 2.出现如下界面后点击 Artifacts--> 绿色加号-->Web Application:A ...
- NSMapTable
跟NSDictionary用法差不多,不过区别是NSMapTable可以设置内存选项,例如可以设置key跟value的内存属性(weak/strong),从而避免内存泄露. 例如这个+ weakToW ...
- 应用SharedPreference保存程序的配置信息
SharedPreference: 1.用来保存应用程序的配置信息的XML文件,内部的数据形式为键值对 2.一般存在于/data/data/<包名>shared_prefs目录下 3.该对 ...
- 关于maven中的快照版本(snapshot)与正式版本(release)解析。
Maven中建立的依赖管理方式基本已成为Java语言依赖管理的事实标准,Maven的替代者Gradle也基本沿用了Maven的依赖管理机制.在Maven依赖管理中,唯一标识一个依赖项是由该依赖项的三个 ...
- 【377】only one element in a tuple
Recently I am doing the assignment of COMP9021. It is too difficult and it is about the Knight and K ...
- SQL--结构化的查询语言
SQL--结构化的查询语言T-SQL:Transact-SQL (SQL的增强版) 逻辑运算符 and && or || not ! 关系运算符 等于 = 不等于<>或!= ...
- freemarker取数
在后端map必须的键值必须是字符串 java.util.Map busVoltagesMap = new java.util.HashMap(); busVoltagesMap.put("1 ...
- jenkins 添加节点问题
没有 Launch agent via Java Web Start 选项 Manage Jenkins > Configure Global Security > TCP port fo ...
- go module 命令
项目目录下,执行以下命令初始化 go mod init 执行以下命令会自动分析项目里的依赖关系同步到go.mod文件中,同时创建go.sum文件 go mod tidy 以上的管理依赖管理操作,所以依 ...