views:

181

answers:

1

Hope I can get some help with a rather obscure problem with UILabel. I keep getting problems with clipping of characters. The font in the image at the link below is baskerville-bolditalic. The yellow is the rect that the UIButton is rendered in. The yellow is the UIButton's titleLabel.backgroundColor.

http://img5.imageshack.us/img5/2381/screenshot20100813at235.png

Here is the code:

    UIButton * currentCharacter = [UIButton buttonWithType:UIButtonTypeCustom];
    currentCharacter.frame = cFrame;
    currentCharacter.backgroundColor = [UIColor blueColor];
        currentCharacter.titleLabel.backgroundColor = [UIColor yellowColor];
        currentCharacter.titleLabel.numberOfLines = 1;
        currentCharacter.titleLabel.adjustsFontSizeToFitWidth = YES;
        currentCharacter.titleLabel.minimumFontSize = 1;
        currentCharacter.titleLabel.font = currentFont;
        currentCharacter.titleLabel.clipsToBounds = NO;
        currentCharacter.clipsToBounds = NO;

        currentCharacter.titleLabel.textAlignment = UITextAlignmentCenter;
        currentCharacter.titleLabel.adjustsFontSizeToFitWidth = YES;

Maybe I'm just misunderstanding adjustsFontSizeToFitWidth. Thanks a ton in advance!

A: 

How did you calculate cFrame ? And maybe the issue is with confusion of assigning the frame (= outer size) vs. bounds (= inner size) ?

DarkDust
cFrame is the square that is blue. It is made with a CGRectMake. I really think the problem is with the UILabel. It doesn't seem to matter what the font size is. I get clipping either way, and it seems to be the label that is squeezing in too much.
Dillon
I don't see you adjusting the titleLabel's size here, have you tried explicitly setting `currentCharacter.titleLabel.frame = currentCharacter.bounds` ? Or if you initialized it that way, have you set `currentCharacter.titleLabel.autoresizingMask = UIViewAutoResizingFlexibleWidth | UIViewAutoResizingFlexibleHeight` so it automatically adjusts its size according to its parent ?
DarkDust