I have a custom "button" (not a UIButton subclass) in a stack view in the header area of my main view (see images). The header shows an image, labels, and the custom button on the first page, and only the title on subsequent pages.
I re-create my pages during size changes (rotation, multitasking, etc...) because the amount of text on each page changes. For some reason, the pages that are created during the size change do not hide the text of my custom button. Subsequent lazily-loaded pages do not exhibit this problem.
I've tried setting the alpha of this button to 0 in addition to hiding it, which has no effect. I also tried calling setNeedsDisplay on the possibility that it may just be a problem with drawing but this doesn't help either.
I would certainly like to understand what's going on here. I've had numerous problems with bugs related to showing and hiding arrangedSubviews, and in some cases have just resorted to completely re-creating the stack view with the appropriate subviews instead of trying to use the hidden property.
Here's the code related to my stack view:
- (void)setOnlyShowTitle:(BOOL)onlyShowTitle{
_onlyShowTitle = onlyShowTitle;
self.lessonTitleLabel.numberOfLines = onlyShowTitle ? 1 : 2;
CGFloat spacing = onlyShowTitle ? 0.0 : 8.0;
self.ierStack.spacing = spacing;
self.leftStack.spacing = spacing;
self.rightStack.spacing = spacing;
BOOL hidden = onlyShowTitle;
self.courseTitleLabel.hidden = hidden;
self.likesView.hidden = hidden; // This is my custom button
self.likesView.alpha = hidden ? 0.0 : 1.0; // This doesn't help
self.ierStack.arrangedSubviews.firstObject.hidden = hidden; // Image View
self.imageView.hidden = hidden;
[self.likesView setNeedsDisplay]; // This doesn't help either
[self setNeedsDisplay];
}
And the constraints on my custom button (consisting of a regular UIButton plus an extra label):
[self.button mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(self);
make.top.equalTo(self);
make.bottom.equalTo(self);
}];
[self.label mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(self.button.mas_trailing).with.offset(8.0);
make.trailing.equalTo(self.mas_trailing);
make.baseline.equalTo(self.button);
}];


