Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension EmptyViewBanner {
var emptyViewText: String {
get {
guard let label = bannerContainerView.viewWithTag(10000) as? UILabel else { return "" }
return label.text ?? ""
}
set {
guard newValue.isEmpty == false else {
bannerContainerView.viewWithTag(10000)?.removeFromSuperview()
return
}
if bannerContainerView.viewWithTag(10000) == nil {
let label = UILabel()
label.numberOfLines = 0
label.tag = 10000
label.textAlignment = .center
label.translatesAutoresizingMaskIntoConstraints = false
bannerContainerView.addSubview(label)
label.leadingAnchor.constraint(equalToSystemSpacingAfter: bannerContainerView.safeAreaLayoutGuide.leadingAnchor, multiplier: 1.0).isActive = true
bannerContainerView.safeAreaLayoutGuide.trailingAnchor.constraint(equalToSystemSpacingAfter: label.trailingAnchor, multiplier: 1.0).isActive = true
label.centerYAnchor.constraint(equalTo: bannerContainerView.safeAreaLayoutGuide.centerYAnchor).isActive = true
}
guard let label = bannerContainerView.viewWithTag(10000) as? UILabel else { fatalError() }
label.text = newValue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment