views:

92

answers:

2

Is there a way to auto size a UILabel? given size 40 x 40 the text font size would adjust based on the number of characters.

A: 

uhm, did you check out the UILabel API http://developer.apple.com/iphone/library/documentation/uikit/reference/UILabel_Class/Reference/UILabel.html there's a neat property called adjustsFontSizeToFitWidth

lwe
sorry im new to obj c
Yolanda
no worries :) sorry, that I didn't provide any sample code. Besides the Apple Docs are very valuable and useful.
lwe
A: 

You can use the adjustFontSizeToFitWidth property. So something like this.

UILabel *myLabel = [[UILabel alloc] init];
[myLabel setAdjustFontSizeToFitWidth:YES];

In Interface Builder there is a check box on the Label Attributes screen to allow you to adjust the font size to fit the label as well.

Jergason
thanks for the sample code
Yolanda
No problem. Sorry, the sample code used to read adjustFontSizeToWidth, but it should be adjustFontSizeToFitWidth. I corrected it.
Jergason