I am loading a custom XIV UIView file as a uitableview header inside a view controller.
The file owner for the xib file is the view manager. I have both a viewcontroller and a uiview interface declared inside a uiviewcontroller.
ViewController.h
@class ZeroStateView; @interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> @property (nonatomic, weak) IBOutlet CustomUITableView *tableView; @property (nonatomic,strong) NSMutableArray *dataArray; @property (weak, nonatomic) IBOutlet ZeroStateView *zeroStateView; @end @interface ZeroStateView : UIView @property (weak, nonatomic) IBOutlet AutoLayoutLabel *titleLabel; @property (weak, nonatomic) IBOutlet UIImageView *titleIcon; - (void)updateView; @end
ViewController.m
- (void)prepareHeaderViewForZeroState{ ZeroStateView *sizingView = [ZeroStateView new]; [[[NSBundle mainBundle] loadNibNamed:@"ZeroStateView" owner:self options:nil] objectAtIndex:0]; sizingView = self.zeroStateView; [sizingView updateView]; self.tableView.tableHeaderView = sizingView; UIView *headerView = self.tableView.tableHeaderView; CGFloat height = [headerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; CGRect headerFrame = headerView.frame; headerFrame.size.height = height; headerView.frame = headerFrame; self.tableView.tableHeaderView = headerView; } @end @implementation ZeroStateView -(void)updateView{ self.titleIcon.alpha = 0.5; UIFontDescriptor *titleFontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleSubheadline]; self.titleLabel.text = @"This is a long text message and its really long. This is a long text message and its really long. This is a long text message and its really long. This is a long text message and its really long. This is a long text message and its really long. This is a long text message and its really long. This is a long text message and its really long. This is a long text message and its really long. "; }
The AutolayoutLabel class overrides the following method:
- (void)setBounds:(CGRect)bounds { [super setBounds:bounds]; // For multiline label, preferredMaxLayoutWidth always matches the frame width if (self.numberOfLines == 0 && bounds.size.width != self.preferredMaxLayoutWidth) { self.preferredMaxLayoutWidth = self.bounds.size.width; [self setNeedsUpdateConstraints]; } }
The height calculated by the system LayoutSizeFittingSize: UILayoutFittingCompressedSize returns 0. As a result, as a view of the table header, I get the following view: 
When I added the actual height as shown below, the uilabel overflows. I expect uiview to grow as the label height grows.
headerFrame.size.height = self.sizingView.frame.size.height;

Here is a screen shot of the limitations of UIViews:

What am I missing here? Can someone point me?
Update I created a sample project so that you guys can check what exactly produces.