-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathErrorView.swift
More file actions
50 lines (39 loc) · 1.8 KB
/
ErrorView.swift
File metadata and controls
50 lines (39 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// ErrorView.swift
// Example
//
// Created by Alexander Schuch on 29/08/14.
// Copyright (c) 2014 Alexander Schuch. All rights reserved.
//
import UIKit
class ErrorView: BasicPlaceholderView {
let textLabel = UILabel()
let detailTextLabel = UILabel()
let tapGestureRecognizer = UITapGestureRecognizer()
override func setupView() {
super.setupView()
backgroundColor = UIColor.white
self.addGestureRecognizer(tapGestureRecognizer)
textLabel.text = "Something went wrong."
textLabel.numberOfLines = 0
textLabel.textAlignment = .center
textLabel.translatesAutoresizingMaskIntoConstraints = false
centerView.addSubview(textLabel)
detailTextLabel.text = "Tap to reload"
detailTextLabel.numberOfLines = 0
detailTextLabel.textAlignment = .center
let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: UIFont.TextStyle.footnote)
detailTextLabel.font = UIFont(descriptor: fontDescriptor, size: 0)
detailTextLabel.textAlignment = .center
detailTextLabel.textColor = UIColor.gray
detailTextLabel.translatesAutoresizingMaskIntoConstraints = false
centerView.addSubview(detailTextLabel)
let views = ["label": textLabel, "detailLabel": detailTextLabel]
let hConstraints = NSLayoutConstraint.constraints(withVisualFormat: "|-[label]-|", options: .alignAllCenterY, metrics: nil, views: views)
let hConstraintsDetail = NSLayoutConstraint.constraints(withVisualFormat: "|-[detailLabel]-|", options: .alignAllCenterY, metrics: nil, views: views)
let vConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|-[label]-[detailLabel]-|", options: .alignAllCenterX, metrics: nil, views: views)
centerView.addConstraints(hConstraints)
centerView.addConstraints(hConstraintsDetail)
centerView.addConstraints(vConstraints)
}
}