热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

swiftImagePicker,第一次迭代

篇首语:本文由编程笔记#小编为大家整理,主要介绍了swiftImagePicker,第一次迭代相关的知识,希望对你有一定的参考价值。

篇首语:本文由编程笔记#小编为大家整理,主要介绍了swift ImagePicker,第一次迭代相关的知识,希望对你有一定的参考价值。




import UIKit
import Kingfisher
protocol ImagPickerProtocol {
var onImageClick: ((_ collectionView: UICollectionView, _ indexPath: IndexPath) -> ())? {get set}
}
class ImagePicker: UICollectionView, ImagPickerProtocol {

var onImageClick: ((_ collectionView: UICollectionView, _ indexPath: IndexPath) -> ())?
var images = [String]()
var max = 5

override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
setupSelf()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupSelf()
}

private func setupSelf() {
backgroundColor = UIColor.white
dataSource = self
delegate = self
}
}
extension ImagePicker: UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "pictureCell", for: indexPath) as! PictureCell
let size = images.count
if (indexPath.row == size) { cell.backgroundColor = UIColor.gray }
else {
let url = URL(string: images[indexPath.row])
cell.picture.kf.setImage(with: url)
}
return cell
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let size = images.count
if (size return size
}
}
extension ImagePicker: UICollectionViewDelegateFlowLayout {

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
onImageClick?(collectionView, indexPath)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 100, height: 100)
}
}


import UIKit
class CreateOfferViewController: BaseViewController, CreateOfferViewInput {

var imagePicker: ImagePicker?
var viewBuilder: ViewBuilder?

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = UIColor.white
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
imagePicker = ImagePicker(frame: CGRect(x: 0, y: 16, width: view.bounds.width, height: 100), collectionViewLayout: layout)
imagePicker?.OnImageClick= { [weak self] (collectionView, indexPath) in
let ipk = UIImagePickerController()
self?.present(ipk, animated: true, completion: nil)
}
view.addSubview(imagePicker!)
imagePicker?.register(PictureCell.self, forCellWithReuseIdentifier: "pictureCell")

imagePicker!.images = [
"https://firebasestorage.googleapis.com/v0/b/samuiplus-9d4b0.appspot.com/o/categories%2Foffers%2F-L7ZLum7uwZ7IAS1gP0n%2F-L7bM1f2aYGGwLNCDSNr%2Fimg_1518014663757.jpg?alt=media&token=34095b90-a53a-4413-8e67-f5633d154c1f",
"https://firebasestorage.googleapis.com/v0/b/samuiplus-9d4b0.appspot.com/o/categories%2Foffers%2F-L85HnRFlWJJwZeqHtLn%2F%D0%A1%D1%80%D0%B5%D0%B4%D0%B8-%D1%80%D0%B8%D1%81%D0%BE%D0%B2%D1%8B%D1%85-%D0%BF%D0%BE%D0%BB%D0%B5%D0%B8%CC%86-%D0%BE.-%D0%91%D0%B0%D0%BB%D0%B8-%D0%98%D0%BD%D0%B4%D0%BE%D0%BD%D0%B5%D0%B7%D0%B8%D1%8F.jpg?alt=media&token=96f4fbec-ca21-47ec-a776-af9551413c1a",
"https://firebasestorage.googleapis.com/v0/b/samuiplus-9d4b0.appspot.com/o/categories%2Foffers%2F-L85H0HTGT6s704K8qpt%2Fimages%20(62).jpg?alt=media&token=5b9c2537-2809-45a0-8a7d-48294ae974ca"]
}
}
// MARK: Button Action
extension CreateOfferViewController {

}


import UIKit
class PictureCell: UICollectionViewCell {

var picture = UIImageView()

override init(frame: CGRect) {
super.init(frame: frame)
initPicture()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initPicture()
}

private func initPicture() {
picture.frame = CGRect(x: 0, y: 0, width: self.bounds.width, height: self.bounds.height)
picture.cOntentMode= .center
picture.clipsToBounds = true
picture.backgroundColor = UIColor.black
self.addSubview(picture)
}
}


import UIKit
class ImagePickerViewController: BaseCollectionViewController, ImagePickerViewInput, ImagPickerProtocol {

var onImageClick: ((_ collectionView: UICollectionView, _ indexPath: IndexPath) -> ())?
var images = [String]()
var max = 5

override func viewDidLoad() {
super.viewDidLoad()
}
}
// MARK: UICollectionViewDataSource
extension ImagePickerViewController {

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "pictureCell", for: indexPath) as! PictureCell
let size = images.count
if (indexPath.row == size) { cell.backgroundColor = UIColor.gray }
else {
let url = URL(string: images[indexPath.row])
cell.picture.kf.setImage(with: url)
}
return cell
}

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let size = images.count
if (size return size
}
}
// MARK: UICollectionViewDelegate
extension ImagePickerViewController {

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
onImageClick?(collectionView, indexPath)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 100, height: 100)
}
}


推荐阅读
  • 本文介绍了一款名为TimeSelector的Android日期时间选择器,采用了Material Design风格,可以在Android Studio中通过gradle添加依赖来使用,也可以在Eclipse中下载源码使用。文章详细介绍了TimeSelector的构造方法和参数说明,以及如何使用回调函数来处理选取时间后的操作。同时还提供了示例代码和可选的起始时间和结束时间设置。 ... [详细]
  • 本文详细介绍了Java中vector的使用方法和相关知识,包括vector类的功能、构造方法和使用注意事项。通过使用vector类,可以方便地实现动态数组的功能,并且可以随意插入不同类型的对象,进行查找、插入和删除操作。这篇文章对于需要频繁进行查找、插入和删除操作的情况下,使用vector类是一个很好的选择。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • Oracle分析函数first_value()和last_value()的用法及原理
    本文介绍了Oracle分析函数first_value()和last_value()的用法和原理,以及在查询销售记录日期和部门中的应用。通过示例和解释,详细说明了first_value()和last_value()的功能和不同之处。同时,对于last_value()的结果出现不一样的情况进行了解释,并提供了理解last_value()默认统计范围的方法。该文对于使用Oracle分析函数的开发人员和数据库管理员具有参考价值。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • ScrollView嵌套Collectionview无痕衔接四向滚动,支持自定义TitleView
    本文介绍了如何实现ScrollView嵌套Collectionview无痕衔接四向滚动,并支持自定义TitleView。通过使用MainScrollView作为最底层,headView作为上部分,TitleView作为中间部分,Collectionview作为下面部分,实现了滚动效果。同时还介绍了使用runtime拦截_notifyDidScroll方法来实现滚动代理的方法。具体实现代码可以在github地址中找到。 ... [详细]
  • C#多线程解决界面卡死问题的完美解决方案
    当界面需要在程序运行中不断更新数据时,使用多线程可以解决界面卡死的问题。一个主线程创建界面,使用一个子线程执行程序并更新主界面,可以避免卡死现象。本文分享了一个例子,供大家参考。 ... [详细]
  • html结构 ... [详细]
author-avatar
bianbianxiong
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有