Open CYZZ opened 8 years ago
Seems like the constraints for contentView inside UIScrollView+EmptyDataSet.h are incomplete. The code on 920 line sets centerX, centerY and Width but no height for contentView that actually contains custom view.
NSLayoutConstraint *centerXConstraint = [self equallyRelatedConstraintWithView:self.contentView attribute:NSLayoutAttributeCenterX];
NSLayoutConstraint *centerYConstraint = [self equallyRelatedConstraintWithView:self.contentView attribute:NSLayoutAttributeCenterY];
[self addConstraint:centerXConstraint];
[self addConstraint:centerYConstraint];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|" options:0 metrics:nil views:@{@"contentView": self.contentView}]];
// When a custom offset is available, we adjust the vertical constraints' constants
if (self.verticalOffset != 0 && self.constraints.count > 0) {
centerYConstraint.constant = self.verticalOffset;
}
This means that contentView height is 0.
I'd propose get rid of that centre constrains and change them to something like that all in one with vertical offset
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|" options:0 metrics:nil views:@{@"contentView": self.contentView}]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat: @"V:|-%f-[contentView]|",self.verticalOffset] options:0 metrics:nil views:@{@"contentView": self.contentView}]];
Changing the constraints as suggested fixes this one case but breaks all other use cases of the library. Since the view that is shown participates in auto layout you can instead create a UIView
subclass and have it return a custom intrinsicContentSize
.
Does someone have a sample project on how to create a custom view? It will be greatly appreciated :)
Project no, but here's example of implementation And how the view is initialised.
You should just get rid of extra constarints
open func customView(forEmptyDataSet scrollView: UIScrollView!) -> UIView? {
let emptyView : EmptyStateBaseView = EmptyStateBaseView.view(delegate: nil, viewSize: self.emptyStateViewSize)
emptyView.emptyImageView.image = UIImage.init(named:"favorites_emptystate")
emptyView.emptyTitleLabel.text = LS("my_zone_empty_favorites_title")
emptyView.emptySubtitleLabelText = LS("my_zone_empty_favorites_sub_title")
emptyView.emptySubtitleLabel.text = LS("my_zone_empty_favorites_sub_title")
emptyView.containerWidthLayoutConstaint.constant = self.traitCollection.horizontalSizeClass != .compact ? 380 : scrollView.size.width - 40.0
return emptyView
}
On Jan 18, 2017, at 10:40, Jayven N notifications@github.com wrote:
Does someone have a sample project on how to create a custom view? It will be greatly appreciated :)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
I just want to return a UIView that fills my collection view with a background of black color
i tried this hack and worked. i think there is something wrong with lib.
func customView(forEmptyDataSet scrollView: UIScrollView!) -> UIView! {
let view = UIView()
view.backgroundColor = UIColor.black
view.frame = CGRect(x: 0, y: 0, width: scrollView.bounds.width, height: scrollView.bounds.height)
scrollView.addSubview(view)
return nil
}
CustomVeiw must add height constriant,frame dosen't work
the view is can't see.how to set customView,from top replace center。