I have problems with auto layout and the UITableView header (tableHeaderView) in iOS 8.X e iOS7.x.
The self.HeaderView
is a XIB built using auto layout.
It's used inside a scrollviewer followed by other views and the result is correct.
Then I set it as header of a table view (as described here):
self.tableView.tableHeaderView = self.HeaderView;
[self.HeaderView setNeedsLayout];
[self.HeaderView layoutIfNeeded];
CGSize headerViewSize = [self.HeaderView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
CGRect frame = self.HeaderView.frame;
frame.size.height = headerViewSize.height;
self.HeaderView.frame = frame;
self.tableView.tableHeaderView = self.HeaderView;
but the resulted height is bigger than expected. I can't understand why. Constraints seem to be ok otherwise why in the scrollview the result is correct?
If in the IB I resize the height of the container frame the constraints are updated without any ambiguity.
Why the UILayoutFittingCompressedSize
doesn't compress the view?
#update
I discovered the problem. Basically the constraints are correct.
After layoutSubviews has been called the UIImageView is correctly sized. Width and height are as expected.
The problem is in the way systemLayoutSizeFittingSize:UILayoutFittingCompressedSize
works.
Instead of calculating the size using the UIImageView size (which has been correctly resized), it uses the size of UIImage (which source file is bigger)
So, what can I do to force systemLayoutSizeFittingSize:UILayoutFittingCompressedSize
to calculate the size using the UIImageView size??