Question

I have created a UILabel that displays a single large character. Even with clipsToBounds = NO; I still get clipping.

See link: http://img341.imageshack.us/img341/5310/screenshot20100814at243.png

I used the following code:

 CGSize fBounds = [myLabel.text sizeWithFont:cFont];

To get what should be the bounding rectangle of the font. And the label is drawn with:

myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 280, 300)];
 myLabel.clipsToBounds = NO;
 myLabel.numberOfLines = 1;
 myLabel.textAlignment = UITextAlignmentCenter;
 myLabel.adjustsFontSizeToFitWidth = YES;
 myLabel.minimumFontSize = 10;
 myLabel.text = @"A";
 myLabel.font = [UIFont fontWithName:@"CourierNewPSMT" size:300];
 myLabel.textColor = [UIColor blackColor];
 myLabel.backgroundColor = [UIColor colorWithRed:1 green:.5 blue:0 alpha:.5];

In the image below, the size returned from sizeWithFont is rendered by the semi-transparent blue rectangle overlay. As you can see, with an italic font (in this case Verdana-BoldItalic), the character extends past what sizeWithFont returns. Further, the UILabel's frame (the orange color) also clips the character. Thoughts? Maybe I could override some text drawing routine. Also, not sure if this is the same problem as here:

UIButton.titleLabel clipping text problem

Was it helpful?

Solution 2

Looks like this is an apple problem. Ended up doing custom drawing with CoreText.

OTHER TIPS

Use attributed text + indent...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top