xib中l(wèi)abel多行顯示的高度問(wèn)題

用xib自定義cell時(shí),給label的添加約束:(top:10,? leading:10,? trailing:10,? height:10)

注:label設(shè)置numberOfLines = 0, 多行顯示的.

問(wèn)題:

當(dāng)用代碼修改height的約束時(shí),報(bào)下面的錯(cuò).

不用代碼修改height的約束時(shí), 錯(cuò)誤消失.???

解決方法:

刪除height的約束,label會(huì)自適應(yīng),label的高度可以計(jì)算出來(lái),用boundingRectWithSize

然后計(jì)算出cell的高度.

錯(cuò)誤信息:

Unable to simultaneously satisfy constraints.Probably at least one of the constraints in the following list is one you don't want.

?Try this: (1) look at each constraint and try to figure out which you don't expect;

?(2) find the code that added the unwanted constraint or constraints and fix it.

(

"<NSLayoutConstraint:0x7d1b1630 UIImageView:0x7d1b1520.height == 40>"

"<NSLayoutConstraint:0x7d1bb780 UILabel:0x7d1b0920.height == 225.031>"

"<NSLayoutConstraint:0x7d1b0cc0 UIImageView:0x7d1b0bb0.height == 20>"

"<NSLayoutConstraint:0x7d1b1bc0 UIButton:0x7d1b1a60.height == 30>"

"<NSLayoutConstraint:0x7d1b1000 UIImageView:0x7d1b0f20.height == 1>"

"<NSLayoutConstraint:0x7d1bccb0 UIImageView:0x7d1b1520.top == UITableViewCellContentView:0x7d1b1420.top + 5>"

"<NSLayoutConstraint:0x7d1bcd40 UILabel:0x7d1b0920.top == UIImageView:0x7d1b1520.bottom + 10>"

"<NSLayoutConstraint:0x7d1bd350 UIView:0x7d1bc7d0.top == UILabel:0x7d1b0920.bottom + 10>"

"<NSLayoutConstraint:0x7d1bd470 UIImageView:0x7d1b0f20.top == UIView:0x7d1bc7d0.bottom + 10>"

"<NSLayoutConstraint:0x7d1be6c0 UIButton:0x7d1b1a60.top == UIImageView:0x7d1b0f20.bottom>"

"<NSLayoutConstraint:0x7d1be6f0 UITableViewCellContentView:0x7d1b1420.bottom == UIImageView:0x7d1b0bb0.bottom>"

"<NSLayoutConstraint:0x7d1be720 UIImageView:0x7d1b0bb0.top == UIButton:0x7d1b1a60.bottom>"

"<NSLayoutConstraint:0x7d75eb20 UITableViewCellContentView:0x7d1b1420.height == 217.375>"

)

Will attempt to recover by breaking constraint

"<NSLayoutConstraint:0x7d1bb780 UILabel:0x7d1b0920.height == 225.031>"

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.

The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 寫(xiě)在前面 iOS的的布局機(jī)制「auto layout」不是一個(gè)新概念,它早在iOS 6中就推出來(lái)了,當(dāng)下距離iOS...
    西門(mén)淋雨閱讀 1,625評(píng)論 2 4
  • Note from Ray:Tutorial Team member Matthijs Hollemans (th...
    Samboo閱讀 591評(píng)論 2 1
  • 一、前言 關(guān)于蘋(píng)果的布局一直是我比較糾結(jié)的問(wèn)題,是寫(xiě)代碼來(lái)控制布局,還是使用storyboard來(lái)控制布局呢?以前...
    iplaycodex閱讀 2,764評(píng)論 0 1
  • 一縷清風(fēng)走過(guò) 掀起我那青絲 隨風(fēng)飄蕩著 桂枝何時(shí)蒙上一層花蕾 池塘里的睡蓮何時(shí)睜開(kāi)眼 不知,銀杏已換了季 ...
    宸淏閱讀 190評(píng)論 0 0
  • 初戀是第一個(gè)喜歡的人吧,那時(shí)候的喜歡很純粹對(duì)方的一個(gè)笑容一句溫柔話語(yǔ)足以讓你興奮一整天甚至夜晚時(shí)候還在床上翻來(lái)覆去...
    許知顏閱讀 527評(píng)論 2 2

友情鏈接更多精彩內(nèi)容