UITableViewCell
and UITableViewHeaderFooterView
using Autolayout
layout [ Xib
, StoryBoard
, Masonry
, SnapKit
, SDAutoLayout
...], supports horizontal and vertical screens, automatically manages the height cache internally, and is compatible with Swift. pod 'UITableViewDynamicLayoutCacheHeight'
pod install
#import <UITableViewDynamicLayoutCacheHeight/UITableViewDynamicLayoutCacheHeight.h>
pod 'UITableViewDynamicLayoutCacheHeight/Category'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate UITableViewDynamicLayoutCacheHeight, add the following to your Cartfile.
github "liangdahong/UITableViewDynamicLayoutCacheHeight" ~> 5.2 . 0
clone https://github.com/liangdahong/UITableViewDynamicLayoutCacheHeight.git
]UITableViewDynamicLayoutCacheHeight
folder into your project. Cell
is built using Xib
"It also supports pure code layout, as long as Autolayout is used."- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
. UITableView
has自动算高
and自动缓存高度
. The effect is as follows: Swift Xib Demo
Swift pure code layout demo
For more usage, please refer to the API of the UITableView+BMDynamicLayout.h file.
Create the Cell in advance, then fill in the content, then force layout, then get the View with the largest MaxY in the Cell, and then take the MaxY of this View to be the height required by the Cell [so保证Cell 中的View 的MaxY 最大的值即为Cell 需要的高度
Crucial], the cache saving and clearing operations are automatically managed internally.
Everyone should be well aware of the shortcomings of the system's automatic high calculation, such as: no caching, repeated calculations, interface jumps, and because it is scrolling and calculating in cells with complex layouts, there are some problems. It only supports iOS8+, and the layout must fill the entire Cell. In the layout In some scenarios, priority needs to be set, otherwise constraint conflicts will be reported.
UITableView-FDTemplateLayoutCell I used this framework at the beginning. At the same time, the API design was also based on FDTemplateLayoutCell. I also used a few materials. Thanks for this, but there are some bugs that have not been solved. The layout must fill the entire Cell. Some scenes need to set priorities during layout, otherwise constraint conflicts will be reported, so they were migrated to UITableViewDynamicLayoutCacheHeight.
The defects of UITableViewDynamicLayoutCacheHeight are:
Based on this framework, a simple WeChat Moments function was implemented. The WeChat Moments code was casually written a few years ago? I am not ready to adjust it. If you are interested, you can take a look.
UITableViewDynamicLayoutCacheHeight is released under the MIT license. See LICENSE for details.