みなさん、私は TableHeaderView を持っていて、すべてが Autolayout によって管理されます:
上部は
UIImageView
常に 2:1 にする必要があるため、アスペクト比と残りの必要な制約を設定します。4
UIButtons
は常に水平で、高さと幅が同じである必要があります。だから私は等幅と等高さ、そしてアスペクト比1:1で作業しましたそして、私は 0 に設定された 2 つ
UILabels
を持っています。また、 のために、次のようにnumberOfLines
のサブクラスを作成しました。UILabel
preferredMaxLayoutWidth
- (void) layoutSubviews { [super layoutSubviews]; if ( self.numberOfLines == 0 ) { if ( self.preferredMaxLayoutWidth != self.frame.size.width ) { self.preferredMaxLayoutWidth = self.frame.size.width; [self setNeedsUpdateConstraints]; } } }
これは私のコードです:
- (void)initializeHeaderViewLabels
{
//After the Response from my server arrived i set the tableHeaderView with the Textdata
self.tableView.tableHeaderView = nil;
if((self.contentDict[@"title"]) != [NSNull null])
{
self.headerTitleLabel.text = (self.contentDict[@"title"]);
}
if((self.contentDict[@"shortDescription"]) != [NSNull null])
{
self.headerDescriptionLabel.text = (self.contentDict[@"shortDescription"]);
}
[self.headerView setNeedsLayout];
[self.headerView layoutIfNeeded];
CGFloat height = [self.headerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
CGRect headerFrame = self.headerView.frame;
headerFrame.size.height = height;
self.headerView.frame = headerFrame;
[self.tableView setTableHeaderView:self.headerView];
}
サーバーからの画像とテキストを取得するUILabels
ので、応答が到着するまで待たなければならず、それから を呼び出しますinitializeHeaderViewLabels
。
**私の問題は、実行時にtableHeaderViewが大きすぎるため、UILabelsが引き伸ばされ、空白がたくさんあることです。多分私は何かが恋しいですか?