iOS - How to find the right font size (in points) with the same height as a given CGRect?
问题 Heading pretty much explains it. I have an image that I'm drawing text on. I want the text to be sized according to the size of the image and want to find a way to get a height for the font that is just a little shorter than the image itself. 回答1: OK, so for everyone who thinks an iteration is not avoidable: NSString *string = @"The string to render"; CGRect rect = imageView.frame; UIFont *font = [UIFont fontWithSize:12.0]; // find the height of a 12.0pt font CGSize size = [string