iOS實現Cell自適應高度

2021-07-08 11:56:37 字數 731 閱讀 4402

1.實現uitableviewdelegate中的方法

先設定cell的contentview中label根據內容自動換行

numberoflines=0

實現uitableviewdelegate中的方法

- (cgfloat)tableview:(uitableview )tableview estimatedheightforrowatindexpath:(nsindexpath )indexpath

2.根據content view設定cell的frame

先設定cell的contentview中label根據內容自動換行

numberoflines=0

cell根據label大小 修改cell此時的尺寸

cgrect bounds = cell.contentlb.bounds;

bounds.size.height = bounds.size.height + 10;

cell.bounds = bounds;

或者在viewdidload裡寫下這兩句

self.chattableview

.rowheight = uitableviewautomaticdimension;

self.chattableview

.estimatedrowheight = 70

;//這句必須寫上值可以為自己估算的cell的高

cell自適應高度

在自定義layoutsubviews中設定自定義cell的位置和大小 iamgeview super layoutsubviews 讓imgview尺寸和cell大小相同 cgfloat height self.contentview bounds size width self.imgview i...

cell自適應高度

計算高度 計算高度 此方法需要在.h中宣告 cgfloat calculateheightwith student student 計算textfiled高度 計算hobby的高度 cgfloat hobbylabelheight student student context nil option...

cell高度自適應

在做專案的時候我們往往會遇到cell高度自適應的問題,樓主以前也寫過,但是由於時間問題和記憶問題將之跑到九霄雲外了,於是上網查閱資料但是發現網上資料幾乎是千篇一律的又長又臭,簡直難以看下去,於是決定寫上重要方法已做記錄,下面上 我們只需要在 cgfloat tableview uitableview...