Matt Coneybeare


Proper Alignment of UIImage and UILabel When Using UITableViewCellStyleSubtitle

| Comments

I am working on an iPhone App Project for a client and I decided to use the UITableViewCellStyleSubtitle for one of my views. It was easy to setup and it had all the details I needed. The only customization I did was change the detailTextLabel.numberOfLines to 2. So I loaded up my content and to my dismay, the cell is not intelligent enough to line up the labels horizontally across all cells. This really, really bothers me.

Before I set out to create my own class and draw my own labels and images, I thought I would just subclass UITableViewCell and try overriding the layouts for what I needed.

Turns out that was all I needed. After using this subclass instead of a UITableViewCell, I now get my image filling the square (if possible) and the Text Labels all lined up vertically.

This code makes 2 assumptions:

1) You want a square imageView that has a width equal to the height of the cell - 1 (for the separator)
2) You want the image to be aspect fit



My name is Matt Coneybeare, I design and develop for the web, iOS (iPhone, iPad and iPod Touch), and MacOS out of New York City. In 2008 I started a software company called Urban Apps that has made some pretty popular apps such as Ambiance and Hourly News. In 2019, I joined the team at Ticket Evolution as a Senior Software Engineer. My current Stack Overflow reputation is about 27k.

I was a Rockstar a decade ago, but then went back to school and collected a Bachelor's Degree in Computer Science from U.C. Berkeley and a MBA from Quantic. Now I am settled down with my beautiful wife Di and our dog Hamachi. When not at my desk, I love exploring New York City as a Yelp Elite, or training for marathons.

Contact information

Matt Coneybeare