Skip to content

Commit e938695

Browse files
committed
Error view title, message and image added
1 parent 5811fa7 commit e938695

File tree

11 files changed

+104
-29
lines changed

11 files changed

+104
-29
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "doc_fail.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Loading

Example/LoadingViewController/ViewController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ class ViewController: LoadingViewController {
1919
delay(3.0) { [weak self] in
2020
self?.setVisibleScreen(.Loading)
2121
self?.delay(3, closure: { [weak self] in
22+
self?.errorTitle = "Lorem ipsum dolor sit amet, et nisl rebum viderer nam."
23+
self?.errorIcon = UIImage(named: "doc_fail")
24+
self?.errorMessage = "Ne laudem expetendis intellegam nec. Vel eu veritus omnesque, ei dolorem oporteat eos, admodum praesent te vix. Vel albucius oportere euripidis ne. Eum in timeam persius, no labore persequeris per, ea vix adhuc postulant."
2225
self?.setVisibleScreen(.Failure)
26+
self?.delay(1, closure: {
27+
self?.setVisibleScreen(.Loading)
28+
self?.delay(2, closure: { [weak self] in
29+
self?.setVisibleScreen(.Content)
30+
})
31+
})
2332
})
2433
}
2534
}
@@ -29,5 +38,8 @@ class ViewController: LoadingViewController {
2938
// Dispose of any resources that can be recreated.
3039
}
3140

41+
override func loadingViewStyle() -> LoadingViewStyle {
42+
return .Multicolor
43+
}
3244
}
3345

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// UIView+Nib.swift
3+
// Pods
4+
//
5+
// Created by Sapozhnik Ivan on 30.06.16.
6+
//
7+
//
8+
9+
import UIKit
10+
11+
protocol UIViewLoading {}
12+
extension UIView : UIViewLoading {}
13+
14+
extension UIViewLoading where Self : UIView {
15+
16+
static func loadFromNib() -> Self {
17+
let nibName = "\(self)".characters.split{$0 == "."}.map(String.init).last!
18+
let bundle = NSBundle(forClass: self)
19+
let nib = UINib(nibName: nibName, bundle: bundle)
20+
return nib.instantiateWithOwner(self, options: nil).first as! Self
21+
}
22+
}

LoadingViewController/Classes/LoadingViewController.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public class LoadingViewController: UIViewController {
5050
var animationQueue = Array<AnimationDict>()
5151
var currentAnimation: AnimationDict?
5252

53-
var errorTitle: String = NSLocalizedString("Oops, something went wrong", comment: "")
54-
var errorMessage: String?
55-
var errorIcon: UIImage?
56-
var errorAction: String?
53+
public var errorTitle: String = NSLocalizedString("Oops, something went wrong", comment: "")
54+
public var errorMessage: String?
55+
public var errorIcon: UIImage?
56+
public var errorAction: String?
5757

5858
var noDataAction: String?
59-
var moDataMessage: String = NSLocalizedString("No data availabel", comment: "")
59+
public var moDataMessage: String = NSLocalizedString("No data availabel", comment: "")
6060

6161
var contentViewAllwaysAvailabel: Bool = false
6262

@@ -69,6 +69,9 @@ public class LoadingViewController: UIViewController {
6969

7070
func defaultErrorView() -> UIView {
7171
let view = ErrorView.viewWithStyle(errorViewStyle(), actionHandler: nil)
72+
view.title = errorTitle
73+
view.message = errorMessage
74+
view.image = errorIcon
7275
return view
7376
}
7477

@@ -80,23 +83,23 @@ public class LoadingViewController: UIViewController {
8083
return view
8184
}
8285

83-
func loadingViewStyle() -> LoadingViewStyle {
86+
public func loadingViewStyle() -> LoadingViewStyle {
8487
return .Indicator
8588
}
8689

87-
func errorViewStyle() -> ErrorViewStyle {
90+
public func errorViewStyle() -> ErrorViewStyle {
8891
return .Simple
8992
}
9093

91-
func showsErrorView() -> Bool {
94+
public func showsErrorView() -> Bool {
9295
return true
9396
}
9497

95-
func showsNoDataView() -> Bool {
98+
public func showsNoDataView() -> Bool {
9699
return true
97100
}
98101

99-
func showsLoadingView() -> Bool {
102+
public func showsLoadingView() -> Bool {
100103
return true
101104
}
102105

LoadingViewController/Classes/Views/ErrorViews/ErrorView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import UIKit
1010

11-
enum ErrorViewStyle {
11+
public enum ErrorViewStyle {
1212
case Simple
1313
}
1414

@@ -36,7 +36,7 @@ class ErrorView: UIView {
3636

3737
switch style {
3838
case .Simple:
39-
let errorView = SimpleErrorView()
39+
let errorView = SimpleErrorView.loadFromNib()
4040
errorView.action = actionHandler
4141
return errorView
4242
}

LoadingViewController/Classes/Views/ErrorViews/SimpleErrorView.swift

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,19 @@ class SimpleErrorView: ErrorView {
1212

1313
var view: UIView!
1414

15-
private func xibSetup() {
16-
view = loadViewFromNib()
17-
view.frame = bounds
18-
addSubview(view)
15+
@IBOutlet var titleLabel: UILabel!
16+
@IBOutlet weak var imageView: UIImageView!
17+
@IBOutlet var messageLabel: UILabel!
18+
19+
override func didSetTitle() {
20+
titleLabel?.text = title
1921
}
2022

21-
convenience init() {
22-
self.init(frame: CGRectZero)
23-
xibSetup()
23+
override func didSetMessage() {
24+
messageLabel?.text = message ?? ""
2425
}
2526

26-
private func loadViewFromNib() -> UIView {
27-
28-
let bundle = NSBundle(forClass: self.dynamicType)
29-
let name = "\(self.dynamicType)".componentsSeparatedByString(".").last ?? ""
30-
let nib = UINib(nibName: name, bundle: bundle)
31-
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
32-
33-
return view
27+
override func didSetImage() {
28+
imageView?.image = image
3429
}
35-
3630
}

LoadingViewController/Classes/Views/ErrorViews/SimpleErrorView.xib

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969
<constraint firstItem="QG0-nT-4fb" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="50" id="jNT-du-umr"/>
7070
</constraints>
7171
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
72+
<connections>
73+
<outlet property="imageView" destination="pyy-8x-tJd" id="CcE-BQ-SHz"/>
74+
<outlet property="messageLabel" destination="bFX-MB-E6F" id="QhM-rg-P1s"/>
75+
<outlet property="titleLabel" destination="gfN-0e-n0e" id="diR-Ym-7yZ"/>
76+
</connections>
7277
<point key="canvasLocation" x="220" y="437"/>
7378
</view>
7479
</objects>

0 commit comments

Comments
 (0)