I have a UIButton of fixed width and I want to place text in it. Since the size of the String is unknown in advance, I will have to resize the font as I read the String from a flat file. How can I do that? A function similar to the following will be great:
UIFont resizeFontAs:(UIFont)initialFont andStringAs:(NSString*)string andWidthAs:(int)width
Thanks in advance
Edit : This code doesnt seem to work:
// Method for creating button, with background image and other properties
- (UIButton *) getCallAgentButtonWithTitleAs:(NSString *)aTitle andImageAs:(UIImage*)bgImg atIndex:(int)index{
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
aButton.frame = CGRectMake(10, 2+index*50, 300, 48);
aButton.titleLabel.frame = CGRectMake(aButton.titleLabel.frame.origin.x + 25.0, aButton.titleLabel.frame.origin.y, aButton.titleLabel.frame.size.width - 50.0, aButton.titleLabel.frame.size.height);
aButton.titleLabel.adjustsFontSizeToFitWidth = YES;
[aButton setTitle:aTitle forState:UIControlStateNormal];
//aButton.titleLabel.font = [UIFont boldSystemFontOfSize:12];
[aButton setTitleColor:UIColorFromRGB(0xFDD428) forState:UIControlStateNormal];
[aButton setBackgroundImage:bgImg forState:UIControlStateNormal];
[aButton addTarget:self action:@selector(callAgent:) forControlEvents:UIControlEventTouchUpInside];
// set the tag as the index and use it later to obtain the phoneNo
[aButton setTag:index];
return aButton;
}