diff --git a/EmptyPage.podspec b/EmptyPage.podspec index 1777b5f..b39f08d 100644 --- a/EmptyPage.podspec +++ b/EmptyPage.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'EmptyPage' -s.version = '3.0.0' +s.version = '3.1.0' s.summary = 'iOS - 轻量级空白页占位图框架...' s.homepage = 'https://github.com/linhay/EmptyPage' diff --git a/Example/EmptyPage.xcodeproj/project.pbxproj b/Example/EmptyPage.xcodeproj/project.pbxproj index 68c0d1b..7bc66e8 100644 --- a/Example/EmptyPage.xcodeproj/project.pbxproj +++ b/Example/EmptyPage.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ CD056F2F21D0E78200A7F94A /* AutoLayoutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD056F2E21D0E78200A7F94A /* AutoLayoutViewController.swift */; }; CD056F3121D0E78F00A7F94A /* AutoLayoutViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD056F3021D0E78F00A7F94A /* AutoLayoutViewController.storyboard */; }; CD11E2162175C9FF00838D84 /* document.sh in Resources */ = {isa = PBXBuildFile; fileRef = CD11E2152175C9FF00838D84 /* document.sh */; }; + CD5ECAD6226EE63D0075CBD5 /* .travis.yml in Resources */ = {isa = PBXBuildFile; fileRef = CD5ECAD5226EE63D0075CBD5 /* .travis.yml */; }; CDA25D572009A7BD003C0E7E /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CDA25D562009A7BD003C0E7E /* Images.xcassets */; }; CDA25D5D2009E54F003C0E7E /* EmptyStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA25D5C2009E54F003C0E7E /* EmptyStore.swift */; }; CDC946FE22017D6A0037F305 /* DZIndexViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC946FC22017D6A0037F305 /* DZIndexViewController.swift */; }; @@ -45,6 +46,7 @@ CD056F2E21D0E78200A7F94A /* AutoLayoutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoLayoutViewController.swift; sourceTree = ""; }; CD056F3021D0E78F00A7F94A /* AutoLayoutViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AutoLayoutViewController.storyboard; sourceTree = ""; }; CD11E2152175C9FF00838D84 /* document.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = document.sh; path = ../document.sh; sourceTree = ""; }; + CD5ECAD5226EE63D0075CBD5 /* .travis.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = .travis.yml; path = ../.travis.yml; sourceTree = ""; }; CDA25D562009A7BD003C0E7E /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; CDA25D5C2009E54F003C0E7E /* EmptyStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyStore.swift; sourceTree = ""; }; CDC946FC22017D6A0037F305 /* DZIndexViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DZIndexViewController.swift; sourceTree = ""; }; @@ -118,6 +120,7 @@ 607FACF51AFB993E008FA782 /* Podspec Metadata */ = { isa = PBXGroup; children = ( + CD5ECAD5226EE63D0075CBD5 /* .travis.yml */, CD11E2152175C9FF00838D84 /* document.sh */, 72069FE43CCD8BD2766D9ED7 /* EmptyPage.podspec */, A8187284C2035D73F1FEC286 /* README.md */, @@ -231,6 +234,7 @@ CDA25D572009A7BD003C0E7E /* Images.xcassets in Resources */, CD11E2162175C9FF00838D84 /* document.sh in Resources */, CD056F3121D0E78F00A7F94A /* AutoLayoutViewController.storyboard in Resources */, + CD5ECAD6226EE63D0075CBD5 /* .travis.yml in Resources */, 9D9EB3932008853E002264E7 /* EmptyPageForCustom.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Example/EmptyPage/AutoLayoutViewController.swift b/Example/EmptyPage/AutoLayoutViewController.swift index 1808f15..9a83c66 100644 --- a/Example/EmptyPage/AutoLayoutViewController.swift +++ b/Example/EmptyPage/AutoLayoutViewController.swift @@ -61,7 +61,7 @@ class AutoLayoutViewController: UIViewController { onlyTextView.removeFromSuperview() onlyImageView.removeFromSuperview() standardView.removeFromSuperview() - tableView.setEmpty(standardView) + tableView.ep.setEmpty(standardView.mix()) tableView.reloadData() } @@ -69,7 +69,7 @@ class AutoLayoutViewController: UIViewController { onlyTextView.removeFromSuperview() onlyImageView.removeFromSuperview() standardView.removeFromSuperview() - tableView.setEmpty(onlyImageView) + tableView.ep.setEmpty(onlyImageView.mix()) tableView.reloadData() } @@ -77,7 +77,7 @@ class AutoLayoutViewController: UIViewController { onlyTextView.removeFromSuperview() onlyImageView.removeFromSuperview() standardView.removeFromSuperview() - tableView.setEmpty(onlyTextView) + tableView.ep.setEmpty(onlyTextView.mix()) tableView.reloadData() } diff --git a/Example/EmptyPage/DZNEmptyDataSet/DetailViewController.swift b/Example/EmptyPage/DZNEmptyDataSet/DetailViewController.swift index cd6f200..7be7583 100644 --- a/Example/EmptyPage/DZNEmptyDataSet/DetailViewController.swift +++ b/Example/EmptyPage/DZNEmptyDataSet/DetailViewController.swift @@ -32,7 +32,7 @@ class DZDetailViewController: UITableViewController { } func config(emptyPage: EmptyPageView) { - tableView.setEmpty(emptyPage) + tableView.ep.setEmpty(emptyPage) } } diff --git a/Example/EmptyPage/Demos/DemoCollectionViewController.swift b/Example/EmptyPage/Demos/DemoCollectionViewController.swift index 5a27043..0c7cb49 100644 --- a/Example/EmptyPage/Demos/DemoCollectionViewController.swift +++ b/Example/EmptyPage/Demos/DemoCollectionViewController.swift @@ -46,12 +46,12 @@ class DemoCollectionViewController: UIViewController,UICollectionViewDelegate,UI } func getData() { - collectionView.setEmpty(EmptyStore.loading) + collectionView.ep.setEmpty(EmptyStore.loading) collectionView.reloadData() rows = 0 sleep(3) {[weak self] in guard let base = self else { return } - base.collectionView.setEmpty(EmptyStore.custom(block1: base.event1(), block2: base.event2())) + base.collectionView.ep.setEmpty(EmptyStore.custom(block1: base.event1(), block2: base.event2())) base.collectionView.reloadData() } } diff --git a/Example/EmptyPage/Demos/DemoScrollViewController.swift b/Example/EmptyPage/Demos/DemoScrollViewController.swift index 9c20451..2fd3f78 100644 --- a/Example/EmptyPage/Demos/DemoScrollViewController.swift +++ b/Example/EmptyPage/Demos/DemoScrollViewController.swift @@ -31,7 +31,7 @@ class DemoScrollViewController: UIViewController { sleep(3) { self.itemView.removeFromSuperview() sleep(3, mainCall: { - self.scrollView.setEmpty(EmptyStore.custom(block1: { + self.scrollView.ep.setEmpty(EmptyStore.custom(block1: { }, block2: { @@ -59,7 +59,7 @@ extension DemoScrollViewController { } private func buildSubView() { - scrollView.setEmpty(EmptyStore.loading) + scrollView.ep.setEmpty(EmptyStore.loading) scrollView.contentSize = view.bounds.size scrollView.showsVerticalScrollIndicator = false scrollView.showsHorizontalScrollIndicator = false diff --git a/Example/EmptyPage/Demos/DemoTableViewController.swift b/Example/EmptyPage/Demos/DemoTableViewController.swift index 90ce52c..e56c9d5 100644 --- a/Example/EmptyPage/Demos/DemoTableViewController.swift +++ b/Example/EmptyPage/Demos/DemoTableViewController.swift @@ -17,7 +17,7 @@ class DemoTableViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() tableView.separatorStyle = .none - tableView.setEmpty(EmptyStore.loading) + tableView.ep.setEmpty(EmptyStore.loading) tableView.register(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier") getData() } @@ -35,11 +35,11 @@ class DemoTableViewController: UITableViewController { } func getData() { - tableView.setEmpty(EmptyStore.loading) + tableView.ep.setEmpty(EmptyStore.loading) tableView.reloadData() sleep(3) {[weak self] in guard let base = self else { return } - base.tableView.setEmpty(EmptyStore.custom(block1: base.event1(), block2: base.event2())) + base.tableView.ep.setEmpty(EmptyStore.custom(block1: base.event1(), block2: base.event2())) base.tableView.reloadData() } } diff --git a/Example/EmptyPage/HomeViewController.swift b/Example/EmptyPage/HomeViewController.swift index a20c613..4562687 100644 --- a/Example/EmptyPage/HomeViewController.swift +++ b/Example/EmptyPage/HomeViewController.swift @@ -11,320 +11,320 @@ import EmptyPage import Hue class HomeViewController: UITableViewController { - - struct Section { - let title: String - let items: [CellItem] - } - - struct CellItem { - let title: String - let subTitle: String - let event: (() -> ())? - let emptyView: EmptyPageView? - init(title: String, subTitle: String, emptyView: EmptyPageView) { - self.title = title - self.subTitle = subTitle - self.event = nil - self.emptyView = emptyView + struct Section { + let title: String + let items: [CellItem] } - init(title: String, subTitle: String, event: @escaping (() -> ())) { - self.title = title - self.subTitle = subTitle - self.event = event - self.emptyView = nil + struct CellItem { + let title: String + let subTitle: String + let event: (() -> ())? + let emptyView: EmptyPageView? + + init(title: String, subTitle: String, emptyView: EmptyPageView) { + self.title = title + self.subTitle = subTitle + self.event = nil + self.emptyView = emptyView + } + + init(title: String, subTitle: String, event: @escaping (() -> ())) { + self.title = title + self.subTitle = subTitle + self.event = event + self.emptyView = nil + } + } - } - - - var sections = [Section]() - - - override func viewDidLoad() { - super.viewDidLoad() - title = "EmptyPage" - tableView.rowHeight = 50 - tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") - tableView.sectionHeaderHeight = 40 - buildDemos() - buildAutoLayout() - buildSectionForDefault() - buildSectionForCustom() - buildDZNEmptyDataSet() - buildByDribbble() - buildByEmptystat() - } - - func buildAutoLayout() { - let demo = CellItem(title: "AutoLayout 调整示例", subTitle: "", event: { - let vc = UIStoryboard(name: String(describing: AutoLayoutViewController.self), - bundle: nil).instantiateInitialViewController()! - self.navigationController?.pushViewController(vc, animated: true) - }) - sections.append(Section(title: "AutoLayout 调整示例", items: [demo])) - } - - func buildDZNEmptyDataSet() { - let demo = CellItem(title: "DZNEmptyDataSet 示例", subTitle: "https://github.com/dzenbot/DZNEmptyDataSet") { - let vc = DZIndexViewController() - self.navigationController?.pushViewController(vc, animated: true) + + var sections = [Section]() + + + override func viewDidLoad() { + super.viewDidLoad() + title = "EmptyPage" + tableView.rowHeight = 50 + tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") + tableView.sectionHeaderHeight = 40 + buildDemos() + buildAutoLayout() + buildSectionForDefault() + buildSectionForCustom() + buildDZNEmptyDataSet() + buildByDribbble() + buildByEmptystat() } - sections.append(Section(title: "DZNEmptyDataSet", items: [demo])) - } - - func buildDemos() { - let table = CellItem(title: "tableView示例", subTitle: "tableView", emptyView: EmptyPageView()) - let collection = CellItem(title: "collectionView示例", subTitle: "collectionView", emptyView: EmptyPageView()) - let scrollView = CellItem(title: "scrollView示例", subTitle: "scrollView", event: { - let vc = DemoScrollViewController() - self.navigationController?.pushViewController(vc, animated: true) - }) - sections.append(Section(title: "完整示例", items: [table,collection, scrollView])) - } - - func buildByEmptystat() { - var items = [CellItem]() - if true { - // http://emptystat.es/image/167120251047 - let emptyView = EmptyPageView.Template.standard - .change(hspace: .button, value: 30) - .change(vspace: .textWithButton, value: 10) - .change(vspace: .titleWithText, value: 10) - .config(button: { (item) in - item.layer.borderColor = UIColor(hex: "#2ca3fa").cgColor - item.layer.borderWidth = 1 - item.layer.cornerRadius = 5 - item.titleLabel?.font = UIFont.systemFont(ofSize: 14) - item.backgroundColor = .white - item.setTitleColor(UIColor(hex: "#2ca3fa"), for: .normal) - item.contentEdgeInsets = UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 20) + func buildAutoLayout() { + let demo = CellItem(title: "AutoLayout 调整示例", subTitle: "", event: { + let vc = UIStoryboard(name: String(describing: AutoLayoutViewController.self), + bundle: nil).instantiateInitialViewController()! + self.navigationController?.pushViewController(vc, animated: true) }) - .set(image: UIImage(named: "empty-1001")!) - .set(title: "Nobody is following", - color: UIColor(hex: "#536571"), - font: UIFont.boldSystemFont(ofSize: 18)) - .set(text: "Following people helps you keep what they're saying and recommending.", - color: UIColor(hex: "#c3ccd1")) - .set(buttonTitle: "Find interesting people to follow >>") - .set(tap: alertEvent()) - .mix() - .set(backgroundColor: UIColor.white) - let item = CellItem(title: "emptystat.es", - subTitle: "http://emptystat.es/image/167120251047", - emptyView: emptyView) - items.append(item) + sections.append(Section(title: "AutoLayout 调整示例", items: [demo])) } - if true { - // http://emptystat.es/image/162198623343 - let emptyView = EmptyPageView.Template.standard - .change(hspace: .button, value: 80) - .change(height: .button, value: 60) - .change(hspace: .image, value: 15) - .config(button: { (item) in - item.backgroundColor = UIColor(hex: "#0180bf") - item.contentEdgeInsets = UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 20) - }) - .set(image: UIImage(named: "empty-1002")!) - .set(title: "Connection failure", - color: UIColor.black, - font: UIFont.boldSystemFont(ofSize: 24)) - .set(text: "Something has gone wrong with the internet connection. Let's give it another shot.", - color: UIColor.black, - font: UIFont.systemFont(ofSize: 15)) - .set(buttonTitle: "TRY AGAIN") - .set(tap: alertEvent()) - .mix() - let item = CellItem(title: "emptystat.es", - subTitle: "http://emptystat.es/image/162198623343", - emptyView: emptyView) - items.append(item) + func buildDZNEmptyDataSet() { + let demo = CellItem(title: "DZNEmptyDataSet 示例", subTitle: "https://github.com/dzenbot/DZNEmptyDataSet") { + let vc = DZIndexViewController() + self.navigationController?.pushViewController(vc, animated: true) + } + sections.append(Section(title: "DZNEmptyDataSet", items: [demo])) } - sections.append(Section(title: "emptystat.es",items: items)) - } - - func buildByDribbble() { - var items = [CellItem]() - if true { - // https://dribbble.com/shots/2586577-404-page-Illustration - let emptyView = EmptyPageView.Template.standard - .set(image: UIImage(named: "404")!) - .change(vspace: .titleWithText, value: 0) - .set(title: "FILE NOT FOUND", - color: UIColor(hex: "#849aac"), - font: UIFont.boldSystemFont(ofSize: 18)) - .set(text: "Lorem ipsum dolor sit amet.\nconectetur adipscing elit sed do eiusmod", - color: UIColor(hex: "#c5cfd7")) - .config(button: { (item) in - item.isHidden = true + func buildDemos() { + let table = CellItem(title: "tableView示例", subTitle: "tableView", emptyView: EmptyPageView()) + let collection = CellItem(title: "collectionView示例", subTitle: "collectionView", emptyView: EmptyPageView()) + let scrollView = CellItem(title: "scrollView示例", subTitle: "scrollView", event: { + let vc = DemoScrollViewController() + self.navigationController?.pushViewController(vc, animated: true) }) - .set(tap: alertEvent()) - .mix() - .set(backgroundColor: UIColor(hex: "#f5f7f9")) - let item = CellItem(title: "404 page - Illustration", - subTitle: "https://dribbble.com/iftikharshaikh", - emptyView: emptyView) - items.append(item) + sections.append(Section(title: "完整示例", items: [table,collection, scrollView])) } - sections.append(Section(title: "dribbble",items: items)) - } - - func buildSectionForCustom() { - var items = [CellItem]() - if true { - let view = EmptyPageForCustom.initFromNib - view.imageView.image = UIImage(named: "empty") - view.label.text = "Connection failure" - let item = CellItem(title: "自定义样式", - subTitle: "一", - emptyView: .mix(view: view)) - items.append(item) - } - sections.append(Section(title: "自定义样式",items: items)) - } - - func buildSectionForDefault() { - - var items = [CellItem]() - let images = (0...3).map { (item) -> UIImage in - return UIImage(named: "load-\(item)")! + func buildByEmptystat() { + var items = [CellItem]() + + if true { + // http://emptystat.es/image/167120251047 + let emptyView = EmptyPageView.Template.standard + .change(hspace: .button, value: 30) + .change(vspace: .textWithButton, value: 10) + .change(vspace: .titleWithText, value: 10) + .config(button: { (item) in + item.layer.borderColor = UIColor(hex: "#2ca3fa").cgColor + item.layer.borderWidth = 1 + item.layer.cornerRadius = 5 + item.titleLabel?.font = UIFont.systemFont(ofSize: 14) + item.backgroundColor = .white + item.setTitleColor(UIColor(hex: "#2ca3fa"), for: .normal) + item.contentEdgeInsets = UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 20) + }) + .set(image: UIImage(named: "empty-1001")!) + .set(title: "Nobody is following", + color: UIColor(hex: "#536571"), + font: UIFont.boldSystemFont(ofSize: 18)) + .set(text: "Following people helps you keep what they're saying and recommending.", + color: UIColor(hex: "#c3ccd1")) + .set(buttonTitle: "Find interesting people to follow >>") + .set(tap: alertEvent()) + .mix() + .set(backgroundColor: UIColor.white) + let item = CellItem(title: "emptystat.es", + subTitle: "http://emptystat.es/image/167120251047", + emptyView: emptyView) + items.append(item) + } + + if true { + // http://emptystat.es/image/162198623343 + let emptyView = EmptyPageView.Template.standard + .change(hspace: .button, value: 80) + .change(height: .button, value: 60) + .change(hspace: .image, value: 15) + .config(button: { (item) in + item.backgroundColor = UIColor(hex: "#0180bf") + item.contentEdgeInsets = UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 20) + }) + .set(image: UIImage(named: "empty-1002")!) + .set(title: "Connection failure", + color: UIColor.black, + font: UIFont.boldSystemFont(ofSize: 24)) + .set(text: "Something has gone wrong with the internet connection. Let's give it another shot.", + color: UIColor.black, + font: UIFont.systemFont(ofSize: 15)) + .set(buttonTitle: "TRY AGAIN") + .set(tap: alertEvent()) + .mix() + let item = CellItem(title: "emptystat.es", + subTitle: "http://emptystat.es/image/162198623343", + emptyView: emptyView) + items.append(item) + } + + sections.append(Section(title: "emptystat.es",items: items)) } - let attributed = NSMutableAttributedString(string: "Connection", - attributes: [.font : UIFont.boldSystemFont(ofSize: 30), - .foregroundColor: UIColor.red]) - let attributed2 = NSAttributedString(string: " Failure", - attributes: [.font : UIFont.systemFont(ofSize: 20), - .foregroundColor: UIColor.darkText]) - attributed.append(attributed2) - - if true { - let emptyView = EmptyPageView.Template.text.set(text: "Connection failure").mix() - let item = CellItem(title: "纯文字", subTitle: "默认样式", emptyView: emptyView) - items.append(item) + func buildByDribbble() { + var items = [CellItem]() + if true { + // https://dribbble.com/shots/2586577-404-page-Illustration + let emptyView = EmptyPageView.Template.standard + .set(image: UIImage(named: "404")!) + .change(vspace: .titleWithText, value: 0) + .set(title: "FILE NOT FOUND", + color: UIColor(hex: "#849aac"), + font: UIFont.boldSystemFont(ofSize: 18)) + .set(text: "Lorem ipsum dolor sit amet.\nconectetur adipscing elit sed do eiusmod", + color: UIColor(hex: "#c5cfd7")) + .config(button: { (item) in + item.isHidden = true + }) + .set(tap: alertEvent()) + .mix() + .set(backgroundColor: UIColor(hex: "#f5f7f9")) + let item = CellItem(title: "404 page - Illustration", + subTitle: "https://dribbble.com/iftikharshaikh", + emptyView: emptyView) + items.append(item) + } + + sections.append(Section(title: "dribbble",items: items)) } - if true { - let emptyView = EmptyPageView.Template.text.set(attributed: attributed).mix() - let item = CellItem(title: "纯文字", subTitle: "富文本样式", emptyView: emptyView) - items.append(item) + func buildSectionForCustom() { + var items = [CellItem]() + if true { + let view = EmptyPageForCustom.initFromNib + view.imageView.image = UIImage(named: "empty") + view.label.text = "Connection failure" + let item = CellItem(title: "自定义样式", + subTitle: "一", + emptyView: .mix(view: view)) + items.append(item) + } + sections.append(Section(title: "自定义样式",items: items)) } - if true { - let emptyView = EmptyPageView.Template.image - .set(image: UIImage(named: "empty-1002")!) - .change(hspace: .image, value: 10) - .mix() - let item = CellItem(title: "纯图片", subTitle: "默认样式", emptyView: emptyView) - items.append(item) + func buildSectionForDefault() { + + var items = [CellItem]() + let images = (0...3).map { (item) -> UIImage in + return UIImage(named: "load-\(item)")! + } + + let attributed = NSMutableAttributedString(string: "Connection", + attributes: [.font : UIFont.boldSystemFont(ofSize: 30), + .foregroundColor: UIColor.red]) + let attributed2 = NSAttributedString(string: " Failure", + attributes: [.font : UIFont.systemFont(ofSize: 20), + .foregroundColor: UIColor.darkText]) + attributed.append(attributed2) + + if true { + let emptyView = EmptyPageView.Template.text.set(text: "Connection failure").mix() + let item = CellItem(title: "纯文字", subTitle: "默认样式", emptyView: emptyView) + items.append(item) + } + + if true { + let emptyView = EmptyPageView.Template.text.set(attributed: attributed).mix() + let item = CellItem(title: "纯文字", subTitle: "富文本样式", emptyView: emptyView) + items.append(item) + } + + if true { + let emptyView = EmptyPageView.Template.image + .set(image: UIImage(named: "empty-1002")!) + .change(hspace: .image, value: 10) + .mix() + let item = CellItem(title: "纯图片", subTitle: "默认样式", emptyView: emptyView) + items.append(item) + } + + if true { + let emptyView = EmptyPageView.Template.image + .set(images: images, duration: 1.5, repeatCount: 0) + .mix() + let item = CellItem(title: "纯图片", subTitle: "图片组样式", emptyView: emptyView) + items.append(item) + } + + + if true { + let emptyView = EmptyPageView.Template.standard + .set(image: UIImage(named: "empty")!) + .set(title: "Connection failure") + .set(text: "wait for a minture") + .set(buttonTitle: "Try Again") + .change(hspace: .button, value: 40) + .change(vspace: .textWithButton, value: 10) + .set(tap: alertEvent()) + .mix() + + let item = CellItem(title: "标准", subTitle: "默认样式", emptyView: emptyView) + items.append(item) + } + + if true { + let emptyView = EmptyPageView.Template.standard + .config(button: { (item) in + item.setTitleColor(.white, for: .normal) + item.titleLabel?.font = .boldSystemFont(ofSize: 18) + item.backgroundColor = .darkGray + }) + .set(images: images, duration: 1.5, repeatCount: 0) + .set(titleAttributed: attributed) + .set(textAttributed: attributed) + .set(text: "wait for a minture") + .set(buttonTitle: "按钮文本") + .set(tap: alertEvent()) + .mix() + + let item = CellItem(title: "标准", subTitle: "默认样式", emptyView: emptyView) + items.append(item) + } + sections.append(Section(title: "标准样式",items: items)) } - if true { - let emptyView = EmptyPageView.Template.image - .set(images: images, duration: 1.5, repeatCount: 0) - .mix() - let item = CellItem(title: "纯图片", subTitle: "图片组样式", emptyView: emptyView) - items.append(item) + func alertEvent() -> ((EmptyPageForStandard) -> ()) { + return { _ in + let alert = UIAlertController(title: "点击事件",message: nil,preferredStyle: .alert) + let action = UIAlertAction(title: "ok", style: .cancel, handler: nil) + alert.addAction(action) + UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil) + } } - - if true { - let emptyView = EmptyPageView.Template.standard - .set(image: UIImage(named: "empty")!) - .set(title: "Connection failure") - .set(text: "wait for a minture") - .set(buttonTitle: "Try Again") - .change(hspace: .button, value: 40) - .change(vspace: .textWithButton, value: 10) - .set(tap: alertEvent()) - .mix() - - let item = CellItem(title: "标准", subTitle: "默认样式", emptyView: emptyView) - items.append(item) + override func numberOfSections(in tableView: UITableView) -> Int { + return sections.count } - if true { - let emptyView = EmptyPageView.Template.standard - .config(button: { (item) in - item.setTitleColor(.white, for: .normal) - item.titleLabel?.font = .boldSystemFont(ofSize: 18) - item.backgroundColor = .darkGray - }) - .set(images: images, duration: 1.5, repeatCount: 0) - .set(titleAttributed: attributed) - .set(textAttributed: attributed) - .set(text: "wait for a minture") - .set(buttonTitle: "按钮文本") - .set(tap: alertEvent()) - .mix() - - let item = CellItem(title: "标准", subTitle: "默认样式", emptyView: emptyView) - items.append(item) + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return sections[section].items.count } - sections.append(Section(title: "标准样式",items: items)) - } - - func alertEvent() -> ((EmptyPageForStandard) -> ()) { - return { _ in - let alert = UIAlertController(title: "点击事件",message: nil,preferredStyle: .alert) - let action = UIAlertAction(title: "ok", style: .cancel, handler: nil) - alert.addAction(action) - UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil) + + override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + let view = UITableViewHeaderFooterView(reuseIdentifier: "header") + view.textLabel?.text = sections[section].title + return view } - } - - override func numberOfSections(in tableView: UITableView) -> Int { - return sections.count - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return sections[section].items.count - } - - override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - let view = UITableViewHeaderFooterView(reuseIdentifier: "header") - view.textLabel?.text = sections[section].title - return view - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell") - cell.textLabel?.text = sections[indexPath.section].items[indexPath.item].title - cell.detailTextLabel?.text = sections[indexPath.section].items[indexPath.item].subTitle - return cell - } - - - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - let item = sections[indexPath.section].items[indexPath.item] - if item.event != nil { - item.event?() - return + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell") + cell.textLabel?.text = sections[indexPath.section].items[indexPath.item].title + cell.detailTextLabel?.text = sections[indexPath.section].items[indexPath.item].subTitle + return cell } - switch item.subTitle { - case "tableView": - let vc = DemoTableViewController(style: .plain) - navigationController?.pushViewController(vc, animated: true) - case "collectionView": - let vc = DemoCollectionViewController() - navigationController?.pushViewController(vc, animated: true) - case "scrollView": - let vc = DemoScrollViewController() - navigationController?.pushViewController(vc, animated: true) - default: - let vc = UITableViewController(style: .plain) - vc.tableView.separatorStyle = .none - vc.tableView.setEmpty(item.emptyView) - navigationController?.pushViewController(vc, animated: true) + + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let item = sections[indexPath.section].items[indexPath.item] + if item.event != nil { + item.event?() + return + } + switch item.subTitle { + case "tableView": + let vc = DemoTableViewController(style: .plain) + navigationController?.pushViewController(vc, animated: true) + case "collectionView": + let vc = DemoCollectionViewController() + navigationController?.pushViewController(vc, animated: true) + case "scrollView": + let vc = DemoScrollViewController() + navigationController?.pushViewController(vc, animated: true) + default: + let vc = UITableViewController(style: .plain) + vc.tableView.separatorStyle = .none + vc.tableView.ep.setEmpty(item.emptyView) + navigationController?.pushViewController(vc, animated: true) + } + } - } - - + } diff --git a/README.md b/README.md index 066dc99..c1d01fa 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,8 @@ app 显示列表内容时, 在某一时刻可能数据为空(等待网络请求/ - 设置空白页 ```swift - tableView.setEmpty(view: emptyView) - collectionView.setEmpty(view: emptyView) + tableView.ep.setEmpty(view: emptyView) + collectionView.ep.setEmpty(view: emptyView) ``` - 空白页显示与切换 @@ -99,7 +99,7 @@ app 显示列表内容时, 在某一时刻可能数据为空(等待网络请求/ 如果需要切换已显示的空白页可主动触发刷新. ```swift - tableView.setEmpty(view: emptyView) + tableView.ep.setEmpty(view: emptyView) tableView.reloadData() ``` diff --git a/Sources/Core/EmptyPage.swift b/Sources/Core/EmptyPage.swift index 0fb0f6e..e4b8924 100644 --- a/Sources/Core/EmptyPage.swift +++ b/Sources/Core/EmptyPage.swift @@ -22,13 +22,6 @@ import UIKit -protocol EmptyPageProtocol { - var isEmpty: Bool { get } - - func setEmptyView() -} - - public struct EmptyPage { public let base: Base public init(_ base: Base) { diff --git a/Sources/Standard/EmptyView+UIScrollView.swift b/Sources/Standard/EmptyView+UIScrollView.swift index feb45f9..5d25638 100644 --- a/Sources/Standard/EmptyView+UIScrollView.swift +++ b/Sources/Standard/EmptyView+UIScrollView.swift @@ -22,13 +22,22 @@ import UIKit +public extension EmptyPage where Base: UIScrollView { + /// 添加空白页视图 + /// + /// - Parameter view: 模板视图 + func setEmpty(_ template: EmptyPageTemplateProtocol?) { + base.ep.setEmpty(template?.mix()) + } +} + public extension UIScrollView { /// 添加空白页视图 /// /// - Parameter view: `EmptyPageView` - @available(iOS,introduced: 8.0, deprecated: 8.0, renamed: "setEmpty(_:)") + @available(iOS,introduced: 8.0, deprecated: 8.0, renamed: "ep.setEmpty(_:)") func setEmpty(view: EmptyPageView?) { self.setEmpty(view) } @@ -36,15 +45,11 @@ public extension UIScrollView { /// 添加空白页视图 /// /// - Parameter view: `EmptyPageView` + @available(iOS,introduced: 8.0, deprecated: 8.0, renamed: "ep.setEmpty(_:)") func setEmpty(_ view: EmptyPageView?) { self.ep.setEmpty(view) } - /// 添加空白页视图 - /// - /// - Parameter view: 模板视图 - func setEmpty(_ template: EmptyPageTemplateProtocol?) { - self.ep.setEmpty(template?.mix()) - } - } + +