效果:
使用:
这一套封装需要使用几个第三方库:
pod 'ZJTableViewManager', '~> 0.0.9'
pod 'SwiftyStarRatingView'
pod 'ImagePicker'
pod 'SKPhotoBrowser', '~> 5.0.0'
pod install
之后
把文件拖进项目就可以用了
(耦合性很低,里面添加图片、浏览图片的框架很好替换,可以自己根据项目需求定制)
在用到的viewcontroller里面的代码:
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var manager: ZJTableViewManager?
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Demo"
self.manager = ZJTableViewManager(tableView: self.tableView)
//register cell
self.manager?.register(OrderEvaluateCell.self, OrderEvaluateItem.self)
self.manager?.register(ZJPictureTableCell.self, ZJPictureTableItem.self)
//add section
let section = ZJTableViewSection(headerHeight: 10, color: UIColor.init(white: 0.9, alpha: 1))
self.manager?.add(section: section)
//add cells
for i in 0...10 {
//评价cell
section.add(item: OrderEvaluateItem(title: "评价"))
let textItem = ZJTextItem(text: nil, placeHolder: "请在此输入您的评价~", didChanged: nil)
textItem.isHideSeparator = true
section.add(item: textItem)
//图片cell
if i%2 == 1 {
//只展示图片
let pictureItem = ZJPictureTableItem(maxNumber: 5, column: 4, space: 15, width: self.view.frame.size.width, superVC: self, pictures: [#imageLiteral(resourceName: "demo_image_1"),#imageLiteral(resourceName: "demo_image_2"),#imageLiteral(resourceName: "demo_image_3"),#imageLiteral(resourceName: "demo_image_4"),#imageLiteral(resourceName: "demo_image_5")])
pictureItem.type = .read
section.add(item: pictureItem)
}else{
//添加图片
let pictureItem = ZJPictureTableItem(maxNumber: 5, column: 4, space: 15, width: self.view.frame.size.width, superVC: self)
pictureItem.type = .edit
section.add(item: pictureItem)
}
}
}
这就集成完成了,运行之后就是我截屏的效果。里面有两种样式,.read是只读的,用于展示图片,.edit就是用于添加图片。
对了,别忘了在plist文件里面加上权限,不然会crash
Demo地址:
ZJTableViewManager中的PictureDemo