tags:

views:

1948

answers:

2

as title how to fit a text into a UILabel when the width and height is not proportionally. in my application, the label width is 100.0, height is 500.0, and the font size is 400, the result show up in simulator was the text out of frame and cannot display completely, if i enable the auto adjust to fit property, the font size no longer be 400, so any idea can fix this? i know if the text scale not proportionally will look weird but i dont care,pls help

+2  A: 

If you just want to have the label be as large as it needs to be to contain the label, you can set it to larger than it needs to be in any circumstance and align it as necessary.

Another option is this:

label.text = newText;
CGRect bounds = label.bounds;
bounds.size = [newText sizeWithFont:label.font];
label.bounds = bounds;
Ed Marty
thanks your reply but this code i have tried before,it will jus adjust the label size and able to contain the font(large),however the thing i need is fix the label bounds size(small),and the font size(large)able to fit inside the label eventhough the font size are not proportionally
I guess I don't know what exactly you're looking for if not this and not an auto-sized font (which can be accomplished by checking "auto-size" in Interface Builder)
Ed Marty
A: 

Thanks a lot for this answer... It solved me a problem and it was very useful