UITextField adjustsFontSizeToFitWidth
@property(nonatomic) BOOL adjustsFontSizeToFitWidth
Discussion of [UITextField adjustsFontSizeToFitWidth]
Normally, the text field’s content is drawn with the font you specify in the font property. If this property is set to YES, however, and the contents in the text property exceed the text field’s bounding rectangle, the receiver starts reducing the font size until the string fits or the minimum font size is reached. The text is shrunk along the baseline.
The default value for this property is NO. If you change it to YES, you should also set an appropriate minimum font size by modifying the minimumFontSize property.
UITextField adjustsFontSizeToFitWidth example.
textField.font = [UIFont boldSystemFontOfSize:17];
textField.textColor = [UIColor darkGrayColor];
textField.minimumFontSize = 10;
textField.adjustsFontSizeToFitWidth = YES;
textField.textColor = [UIColor darkGrayColor];
textField.minimumFontSize = 10;
textField.adjustsFontSizeToFitWidth = YES;
Example of [UITextField adjustsFontSizeToFitWidth].
//print object's scientific name
dataView = [[UILabel alloc] initWithFrame:CGRectMake(120, 5, 170, 20)];
dataView.text = [detailBird scientificName];
dataView.adjustsFontSizeToFitWidth = YES;
dataView.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
[cell.contentView addSubview:dataView];
[dataView release];
dataView = [[UILabel alloc] initWithFrame:CGRectMake(120, 5, 170, 20)];
dataView.text = [detailBird scientificName];
dataView.adjustsFontSizeToFitWidth = YES;
dataView.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
[cell.contentView addSubview:dataView];
[dataView release];
UITextField adjustsFontSizeToFitWidth example.
//print object's family name
dataView = [[UILabel alloc] initWithFrame:CGRectMake(120, 5, 170, 20)];
dataView.text = [detailBird family];
dataView.adjustsFontSizeToFitWidth = YES;
dataView.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
[cell.contentView addSubview:dataView];
[dataView release];
dataView = [[UILabel alloc] initWithFrame:CGRectMake(120, 5, 170, 20)];
dataView.text = [detailBird family];
dataView.adjustsFontSizeToFitWidth = YES;
dataView.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
[cell.contentView addSubview:dataView];
[dataView release];