RTLabel icon indicating copy to clipboard operation
RTLabel copied to clipboard

frame and height issue

Open amitbattan opened this issue 13 years ago • 2 comments

Hi

there is issue in the RTLabel with its frame. its height is not correct. Always shown only one line of text.

Screen Shot 2013-02-05 at 12 59 45 PM

Log

updateContentLabel.frame : {{0, 0}, {300, 100}} optimumSize of RTLabel : {296.856, 82}

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self rowHeightForRecord:nil];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    float cellWidth = self.tableView.frame.size.width;

// other controls
    RTLabel *updateContentLabel;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DataCell"];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DataCell"] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

// other controls

        updateContentLabel = [[RTLabel alloc] init];
        updateContentLabel.tag = 1006;
        updateContentLabel.backgroundColor = [UIColor redColor];
        updateContentLabel.lineBreakMode = RTTextLineBreakModeWordWrapping;
        updateContentLabel.lineSpacing = 20;
        [cell.contentView addSubview:updateContentLabel];

    } else {
// other controls
        updateContentLabel = (RTLabel *)[cell viewWithTag:1006];
    }

    id record = [activityUpdateArray objectAtIndex:indexPath.row];

    triggeredByAvtar.frame = CGRectMake(10, 10, 25, 25);
    triggeredByAvtar.image = [[StarshipImagesServices shared] getImageWithUrl:[record objectForKey:@"TriggeredByProfileImage"]];
    if ( triggeredByAvtar.image == nil ) {
        triggeredByAvtar.image = [UIImage imageNamed:@"img-fetching.png"];
    }

// other controls

    updateContentLabel.frame = CGRectMake(10, 35, cellWidth-20, 300);
    [self setUpdateContent:updateContentLabel forRecord:record];
    CGSize optimumSize = [updateContentLabel optimumSize];
    updateContentLabel.frame = CGRectMake(0, 0, cellWidth-20, 100); // set height 100 for temporary test

// other controls

    return cell;
}

-(void)setUpdateContent:(RTLabel *)contentLabel forRecord:(id)record {

    NSString *string1 = @"this is blue text this is blue text this is blue text this is blue text this is blue text this is blue text this is blue text this is blue text";
    NSString *string2 = @" black black black black black black ";
    NSString *string3 = @"this is blue text this is blue text this is blue text this is blue text this is blue text";
![Screen Shot 2013-02-05 at 12 59 45 PM](https://f.cloud.github.com/assets/641959/126586/fe601028-6f65-11e2-8503-80343a40c282.png)
    NSString *text = [NSString stringWithFormat:@"<font face='%@' size=12 color='#2E4AF7'>'%@'</font><font face='%@' size=12 color='#000000'> %@ </font><font face='%@' size=12 color='#2E4AF7'>%@</font>", FontRegular, string1, FontRegular, string2, FontRegular, string3];
    contentLabel.text = text;
    [contentLabel setParagraphReplacement:@""];
} 

-(float)rowHeightForRecord:(id)record {
    float cellWidth = self.tableView.frame.size.width;
    NSString *string1 = @"this is blue text this is blue text this is blue text this is blue text this is blue text this is blue text this is blue text this is blue text";
    NSString *string2 = @" black black black black black black ";
    NSString *string3 = @"this is blue text this is blue text this is blue text this is blue text this is blue text";
    NSString *text = [NSString stringWithFormat:@"<font face='%@' size=12 color='#2E4AF7'>'%@'</font><font face='%@' size=12 color='#000000'> %@ </font><font face='%@' size=12 color='#2E4AF7'>%@</font>", FontRegular, string1, FontRegular, string2, FontRegular, string3];
// FontRegular font defined globally, Optima in this case

    RTLabel *rtLabel = [[RTLabel alloc] initWithFrame:CGRectMake(0, 0, cellWidth-20, 300)];
    rtLabel.lineSpacing = 20.0;
    [rtLabel setText:text];
    CGSize optimumSize = [rtLabel optimumSize];
    NSLog(@" / / / /%@/ / / / ", NSStringFromCGSize(optimumSize));
    return optimumSize.height+60;
}

amitbattan avatar Feb 05 '13 07:02 amitbattan

please delete this issue...

amitbattan avatar Feb 05 '13 08:02 amitbattan

I had the same issue, found solution after initialization of RTlLabel with frame of height 100.

RTLabel *yourLabel = [[RTLabel alloc] initWithFrame:CGRectMake(0,0,100,100)]; then assign text n get optimize height and update frame of yourLabel.

adnanbajwa avatar Mar 18 '15 06:03 adnanbajwa