MDHTMLLabel
MDHTMLLabel copied to clipboard
Set frame width/height depends on htmlText
Hi
Its great one, but i'm asking how to take the CGSize for htmlText to set the frame depends on it
I used this one but it doesn't make what I need
NSString *titlec = [NSString stringWithFormat:@"<b>%@</b> %@",thecomment.user.username,thecomment.text];
CGSize size = [self frameForText:titlec sizeWithFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:12.0] constrainedToSize:CGSizeMake(300.f, CGFLOAT_MAX)];
-(CGSize)frameForText:(NSString*)text sizeWithFont:(UIFont*)font constrainedToSize:(CGSize)size{
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
font, NSFontAttributeName,
nil];
CGRect frame = [text boundingRectWithSize:size
options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
attributes:attributesDictionary
context:nil];
// This contains both height and width, but we really care about height.
return frame.size;
}
what were your results? too big of a size? I haven't tried to do this myself but you most likely you need to use the attributed string from the label after setting the html since it's modifies the incoming html string to produce the attributed string.