下面的代碼,我認爲應該在一個多行標籤後面跟一個按鈕,然而,在佈局之後,只有一行標籤顯示出來。雖然我可以在垂直佈局中明確表示高度,但這會破壞目的。關於我應該採用哪些其他限制的任何想法?iOS:多行uilabel只顯示一行自動佈局
UILabel *lbExplain = [[UILabel alloc] init];
lbExplain.text = @"The Sync process allows you to synchronize your library between different devices. By clicking on the button below you can find other devices to sync with. The other device also has to be running this applicaton.";
lbExplain.lineBreakMode = NSLineBreakByWordWrapping;
lbExplain.numberOfLines = 0;
lbExplain.translatesAutoresizingMaskIntoConstraints = NO;
UIButton *btnPartner = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnPartner setTitle:@"Look for Partners" forState:UIControlStateNormal];
[btnPartner addTarget:self action:@selector(findPartners:) forControlEvents:UIControlEventTouchUpInside];
btnPartner.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:lbExplain];
[self.view addSubview:btnPartner];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[lbExplain]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(lbExplain)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[lbExplain]-[btnPartner]" options:NSLayoutFormatAlignAllLeft metrics:nil views:NSDictionaryOfVariableBindings(lbExplain, btnPartner)]];
如果您在標籤上調用'-sizeToFit',會發生什麼? – 2013-02-24 23:51:18
沒有區別。 – ckh 2013-02-25 00:06:12
我看不到缺少的東西。如果你在IB中做基本相同的事情,它可以正常工作。 – rdelmar 2013-02-25 00:26:27