Upvote:0

NSString *[email protected]"some text";
[myLabel setText:labelText];
UIFont *labelTextFont = [UIFont fontWithName:@"Helvetica" size:labelTextsize];
CGSize labelFrameSize = [labelText sizeWithFont:labelTextFont];
myLabel.frame = CGRectMake(xPos, yPos, labelFrameSize.width, labelFrameSize.height);

More Answer related to the Same Query

Upvote:0

UIFont *font =  [UIFont fontWithName:K_FONT_AVENIR_MEDIUM size:textSize];

if ([data isKindOfClass:[NewsModel class]]) {
    NewsModel *news = (NewsModel *)data;

    if (SYSTEM_VERSION_LESS_THAN(@"7.0")) {
        CGSize constraintSize = CGSizeMake(cellTextWidth, MAXFLOAT);
        CGSize textRect = [news.title sizeWithFont:font constrainedToSize:constraintSize];

        return textRect.height + paddingTopAndBottom;
    } else {
        CGRect textRect = [news.title boundingRectWithSize:CGSizeMake(cellTextWidth, CGFLOAT_MAX)
                                                   options:NSStringDrawingUsesLineFragmentOrigin
                                                attributes:@{NSFontAttributeName:font}
                                                   context:nil];

        return textRect.size.height + paddingTopAndBottom;
    }
}

return 0;

Upvote:0

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 GeneralCell* cell      = [tableView dequeueReusableCellWithIdentifier:@"GeneralCell"];
    if (cell == nil) {
        cell = [[GeneralCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GeneralCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    /////// USE the following block if still in trouble 
    CGRect frame = cell.label.frame;      
    [cell.label setFrame:frame];
    [cell.label sizeToFit]; // this should not be necessary in general
    ///////////
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  {
    NSString     *detail   = [NSString stringWithFormat:@"YOUR TEXT]];

    CGSize constraintSize = CGSizeMake(CELL_CONTENT_WIDTH, MAXFLOAT);
    CGSize labelSize = [detail boundingRectWithSize:constraintSize
                                            options:NSStringDrawingUsesLineFragmentOrigin
                                         attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:FONT_SIZE]}
                                            context:nil].size;


    float h = (fmod((int)labelSize.height ,2) == 0) ? labelSize.height : labelSize.height+1;
    CGFloat height = MAX(h, 30.0f);
    elemento = nil;
    detail   = nil;
    return height + (CELL_CONTENT_MARGIN * 2);
}

Credit Goes to: stackoverflow.com

Related question with same questions but different answers