Latest 0.1.1
Homepage https://github.com/danielbowden/DBDynamicHeightTableCell
License MIT
Platforms ios 7.0, requires ARC
Authors

A UITableViewCell subclass for iOS 7 assisting in autolayout based dynamic height cells for tableviews. It uses the recommended approach of creating a prototype cell and using systemLayoutSizeFittingSize to resize the superview to UILayoutFittingCompressedSize to fit all subviews of the cell’s contentView according to their autolayout constraints. Rather than the old method of sizeWithFont etc that is now deprecated.

There is an example project included. Clone the repo and open "DBDynamicHeightTableCellDemo.xcworkspace".

Mentioned by Orta Therox of Cocoapods on his Pod5 podcast – Episode 13.

Usage

Create a DBDynamicHeightTableCell subclass like in the example (InfoCell.h/m/xib).

Implement the abstract method - (void)populateWithObject:(id)object;. This is used to populate your tablecells views. A basic example:

- (void)populateWithObject:(id)object
{
    self.headlineLabel.text = [object headline];
    self.summaryLabel.text = [object summary];
}

Plain text labels

You can even use attributed strings, different font sizes, colors, etc.

- (void)populateWithObject:(id)object
{
    NSAttributedString *attributedHeadline = [[NSAttributedString alloc] initWithString:[object headline] attributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle), NSFontAttributeName: [UIFont boldSystemFontOfSize:16.0], NSForegroundColorAttributeName: [UIColor redColor]}];

    NSAttributedString *attributedSummary = [[NSAttributedString alloc] initWithString:[object summary] attributes:@{NSFontAttributeName: [UIFont italicSystemFontOfSize:14.0]}];

    self.headlineLabel.attributedText = attributedHeadline;
    self.summaryLabel.attributedText = attributedSummary;
}

Attributed text labels

To refer to your cell’s xib implement the abstract method + (UINib *)nib;.

+ (UINib *)nib
{
    return [UINib nibWithNibName:@"InfoCell" bundle:nil];
}

Autolayout constraints

Setup your autolayout constraints for the subviews in your cell so that it knows how it can grow/shrink.

Installation

DBDynamicHeightTableCell is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "DBDynamicHeightTableCell"

Author

Daniel Bowden

github.com/danielbowden

twitter.com/danielgbowden

License

DBDynamicHeightTableCell is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "DBDynamicHeightTableCell",
    "version": "0.1.1",
    "summary": "A UITableViewCell subclass assisting in autolayout based dynamic height cells for tableviews",
    "description": "                       A UITableViewCell subclass assisting in autolayout based dynamic height cells for tableviews. Uses recommended approach creating a prototype cell and systemLayoutSizeFittingSize to resize superview to systemLayoutSizeFittingSize all subviews of the cell's contentView with autolayout. Rather than the old method of sizeWithFont etc. n",
    "homepage": "https://github.com/danielbowden/DBDynamicHeightTableCell",
    "license": "MIT",
    "authors": {
        "Daniel Bowden": "[email protected]"
    },
    "source": {
        "git": "https://github.com/danielbowden/DBDynamicHeightTableCell.git",
        "tag": "0.1.1"
    },
    "screenshots": [
        "https://raw.githubusercontent.com/danielbowden/DBDynamicHeightTableCell/master/Example/Screenshots/DBDynamicHeightTableCell-AttributedLabels.png",
        "https://raw.githubusercontent.com/danielbowden/DBDynamicHeightTableCell/master/Example/Screenshots/DBDynamicHeightTableCell-PlainLabels.png"
    ],
    "social_media_url": "https://twitter.com/danielgbowden",
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "Classes",
    "public_header_files": "Classes/*.h"
}

Pin It on Pinterest

Share This