Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frame and height issue #29

Open
amitbattan opened this issue Feb 5, 2013 · 2 comments
Open

frame and height issue #29

amitbattan opened this issue Feb 5, 2013 · 2 comments

Comments

@amitbattan
Copy link

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
Copy link
Author

please delete this issue...

@adnanbajwa
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants