-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EmptyView #18
Add EmptyView #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// EmptyView.swift | ||
// SB-MDEditor | ||
// | ||
// Created by Антон Заричный on 20.04.2023. | ||
// | ||
|
||
import UIKit | ||
|
||
final class EmptyView: UIView { | ||
private lazy var emptyPictureLabel = makeEmptyPictureLabel() | ||
private lazy var emptyTextLabel = makeEmptyTextLabel() | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
|
||
setup() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
|
||
setup() | ||
} | ||
} | ||
|
||
private extension EmptyView { | ||
func setup() { | ||
backgroundColor = .clear | ||
setupContainer() | ||
} | ||
|
||
func makeEmptyPictureLabel() -> UILabel { | ||
let label = UILabel() | ||
label.text = "📂" | ||
label.font = Theme.font(style: .largeTitle) | ||
return label | ||
} | ||
|
||
func makeEmptyTextLabel() -> UILabel { | ||
let label = UILabel() | ||
label.textColor = Theme.color(usage: .gray) | ||
label.text = "Empty folder" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. если используешь внутренний текст (объявлен внутри класса), то используй такой вариант: // MARK: - Appearance
private extension AboutViewController {
enum Appearance {
static let welcomeText = "Welcome to About"
static let title = "About"
}
} и используй как There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Но этого тебе здесь не надо, нам нужна вьюха, которая принимает картинку и текст. |
||
label.font = Theme.font(style: .title) | ||
return label | ||
} | ||
|
||
func setupContainer() { | ||
let backgroundView = UIView() | ||
backgroundView.backgroundColor = Theme.color(usage: .white) | ||
addSubview(backgroundView) | ||
backgroundView.makeConstraints { make in | ||
[ | ||
make.leadingAnchor.constraint(equalTo: leadingAnchor), | ||
make.trailingAnchor.constraint(equalTo: trailingAnchor), | ||
make.bottomAnchor.constraint(equalTo: bottomAnchor) | ||
] | ||
} | ||
|
||
let stackContainer = UIStackView() | ||
stackContainer.axis = .vertical | ||
stackContainer.distribution = .fill | ||
stackContainer.alignment = .center | ||
stackContainer.spacing = 16 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
let insets = UIEdgeInsets( | ||
top: 0, | ||
left: 16, | ||
bottom: 16, | ||
right: 16 | ||
Comment on lines
+67
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. здесь тоже из темы |
||
) | ||
|
||
[ | ||
emptyPictureLabel, | ||
emptyTextLabel | ||
].forEach { stackContainer.addArrangedSubview($0) } | ||
|
||
backgroundView.addSubview(stackContainer) | ||
stackContainer.makeEqualToSuperview(insets: insets) | ||
} | ||
} | ||
|
||
#if canImport(SwiftUI) && DEBUG | ||
import SwiftUI | ||
struct EmptyViewProvider: PreviewProvider { | ||
static var previews: some View { | ||
let emptyView = EmptyView() | ||
return Group { | ||
VStack(spacing: 0) { | ||
emptyView.preview().frame(height: 100).padding(.bottom, 20) | ||
} | ||
.preferredColorScheme(.light) | ||
} | ||
} | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
по структуре все гуд, как я хочу ленивый элемент = функция make из расширения