DZNEmptyDataSet
DZNEmptyDataSet copied to clipboard
Custom view does not show
I want to show a custom view using this code snippet.
func customView(forEmptyDataSet scrollView: UIScrollView!) -> UIView! {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
view.backgroundColor = .green
return view
}
The view does not show up. What's the issue here? Is it related to autolayout?
@honkmaster you can't just add a view for the customView . you must be add some views ,some buttons or other Controls in the customView , and try again .
i think something wrong with lib. so i tried this and worked.
func customView(forEmptyDataSet scrollView: UIScrollView!) -> UIView! {
let view = EmptyStateView()
view.frame = CGRect(x: 0, y: 0, width: scrollView.bounds.width, height: scrollView.bounds.height)
scrollView.addSubview(view)
return nil
}
EmptyStateView is custom view class, loaded from nib.
Try this
- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView {
UIView *emptyView = [[UIView alloc] init];
UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 130, 40)];
lb.text = @"UILabel";
[emptyView addSubview:lb];
emptyView.backgroundColor = [UIColor redColor];
[emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@180);
}];
return emptyView;
}
I have a customer activity view as below. It doesn't show.
import UIKit
class ProgressHUD: UIVisualEffectView {
var text: String? {
didSet {
label.text = text
}
}
let activityIndictor: UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.white)
let label: UILabel = UILabel()
let blurEffect = UIBlurEffect(style: .dark)
let vibrancyView: UIVisualEffectView
init(text: String) {
self.text = text
self.vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: blurEffect))
super.init(effect: blurEffect)
self.setup()
}
required init?(coder aDecoder: NSCoder) {
self.text = ""
self.vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: blurEffect))
super.init(coder: aDecoder)
self.setup()
}
func setup() {
contentView.addSubview(vibrancyView)
contentView.addSubview(activityIndictor)
contentView.addSubview(label)
activityIndictor.startAnimating()
//UIApplication.shared.beginIgnoringInteractionEvents()
}
override func didMoveToSuperview() {
super.didMoveToSuperview()
if let superview = self.superview {
let width = superview.frame.size.width / 2.3
let height: CGFloat = 50.0
self.frame = CGRect(x: superview.frame.size.width / 2 - width / 2,
y: superview.frame.height / 2 - height / 2,
width: width,
height: height)
vibrancyView.frame = self.bounds
let activityIndicatorSize: CGFloat = 40
activityIndictor.frame = CGRect(x: 5,
y: height / 2 - activityIndicatorSize / 2,
width: activityIndicatorSize,
height: activityIndicatorSize)
layer.cornerRadius = 8.0
layer.masksToBounds = true
label.text = text
label.textAlignment = NSTextAlignment.center
label.frame = CGRect(x: activityIndicatorSize + 5,
y: 0,
width: width - activityIndicatorSize - 15,
height: height)
label.textColor = UIColor.white
label.font = UIFont.boldSystemFont(ofSize: 16)
}
}
func show() {
self.isHidden = false
UIApplication.shared.beginIgnoringInteractionEvents()
}
func hide() {
self.isHidden = true
UIApplication.shared.endIgnoringInteractionEvents()
}
}
my customeView method is
func customView(forEmptyDataSet scrollView: UIScrollView!) -> UIView! {
let progressHUD = ProgressHUD(text: "Loading")
progressHUD.show()
return progressHUD
}
if i return UIActivityIndicatorView then it shows up.