Note that there are some explanatory texts on larger screens.

plurals
  1. POResizing custom UITableViewCell's subviews on creation
    primarykey
    data
    text
    <p>I'm attempting to create a custom UITableViewCell with its own XIB, of which contains two important, editable components:</p> <ul> <li>UILabel</li> <li>UIImage with 'end-cap insets' - this image sits behind the label, and resizes with it</li> </ul> <p>When I create my UITableViewCell I can set its label's text easily, but in the same method I also try to change the UIImage's frame to match that of the UILabel's. However, this is not happening until I 'reload' the cell by scrolling the table view to dequeue it and bring it back into view.</p> <p>I create the custom table view cell in my view controller's .m:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *UITableViewCellIdentifier = @"msgCell"; RMMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:UITableViewCellIdentifier]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MessageCell" owner:self options:nil]; cell = [topLevelObjects objectAtIndex:0]; [cell customInit]; //This sets up the ImageView's image etc } [cell setMessageValue:[_messages objectAtIndex:indexPath.row]]; //SEE BELOW return cell; } </code></pre> <p>...And in my custom cell's .m, I deal with setting the text label and resizing the image with this method:</p> <pre><code>- (void)setMessageValue:(NSString *)message { _testLabel.text = message; // Assume the text label's frame has already been set to the message's length // (will add this in once I figure out how to change the imageView's // frame correctly) // Set the image view's frame to the label's // THIS DOES NOT TAKE EFFECT UNTIL THE TABLE VIEW IS RE-SCROLLED CGRect frame = _imageView.frame; frame.size.width = _testLabel.frame.size.width + 8; _imageView.frame = frame; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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