Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to set a fixed width on the UIImageView inside a UITableViewCell?
    text
    copied!<p>I have a UITableView in which of course I use some UITableViewCells. Now some cells have an icon / image which I want to display in front of the text, and some others don't. I didn't create the UITableViewCells in Interface Builder, just using the default stuff :</p> <p>// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {</p> <pre><code>static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Set up the cell... switch (indexPath.row) { case 0: cell.textLabel.text = @"Nearby"; cell.imageView.image = [UIImage imageNamed:@"marker.png"]; break; case 1: cell.textLabel.text = @"Bookmarked"; cell.imageView.image = [UIImage imageNamed:@"bookmark.png"]; break; case 2: cell.textLabel.text = @"Other"; break; default: break; } return cell; </code></pre> <p>}</p> <p>This seems to be working perfectly, but I have a little issue with the width of the cell.imageView. The icons I'm using seem to have a different width. Some are 21 pixels, others are 25 pixels and in some casts I have no icon at all.</p> <p>This results in the text for the textLabel to appear at different positions (depending on the width of the imageView).</p> <p>Now my question is, can I add some code / statement which will make sure that the imageView of my cell is always 30 pixels wide ? Even if there is no image for that imageView ?</p> <p>Can this be done programatically or will I have to make a Custom Cell in InterfaceBuilder or even create my own UITableViewCell descendant.</p> <p>Any information on this topic is welcome.</p> <p>Regards,</p> <p>Stefaan</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload