I need to fill in a rect with some text. The size of rect is fixed.
I use the following function:
- (void)drawText:(NSString *)text onView:(UIView *)view inRect:(CGRect)rect
{
UILabel *lbl = [[UILabel alloc] initWithFrame:rect];
lbl.minimumFontSize = 1;
lbl.font = [UIFont systemFontOfSize:30];
[lbl setText:text];
lbl.adjustsFontSizeToFitWidth = YES;
[view addSubview:lbl];
[lbl release];
}
Then I write something similar to this:
[self drawText:@"Asdfghjkl;" onView:view inRect:CGRectMake(45, 40, 85, 13)];
[self drawText:@"qwertyui" onView:view inRect:CGRectMake(173, 31, 126, 22)];
And I get the cutted text. Where is my mistake?
I think the main trouble is that some text fits width only but it must fit both width and height.
So the fastest solution for me is to make a bigger transparent UILabel and put a text inside it using alignment