Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent a UILabel cutting off with '...'

I was wondering if there is any way to prevent an UILabel from cutting off with '...'? I have a CGRect which is 55 in width and 20 in height and I would like it to simply cut off after 55 (or clip the contents off) without indicating with '...' that there is more.

        UILabel *btnTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 55, 20)];
    btnTitle.text = labelMe;
    btnTitle.textColor = [UIColor whiteColor];
    btnTitle.backgroundColor = [UIColor clearColor];
    btnTitle.transform = CGAffineTransformMakeRotation( ( 90 * M_PI ) / 180 );

I achieved what I wanted (i.e. the clipping) by putting the UILabel (with increased width, i.e. 100 x 20) into an UIView (55 x 20) and set clipsToBounds to YES with the result that I couldn't click my buttons anymore - because I was using the label to label a button. The UIView containing the label was hiding my buttons...

Is there a way around this without using an UIView to clip the contents of my UILabel?

like image 969
n.evermind Avatar asked Apr 28 '11 20:04

n.evermind


3 Answers

Try this out:

label.lineBreakMode = NSLineBreakByClipping;

For more information, refer UILabel Class Reference

Hope this helps

like image 130
Ole Begemann Avatar answered Nov 10 '22 20:11

Ole Begemann


Use UILineBreakModeClip or one of the other options. Set it with the UILabel lineBreakMode property.

like image 38
jakev Avatar answered Nov 10 '22 19:11

jakev


You can tell your view that contains your label to ignore touches and send them to the next available responder to do this just add this method to your view.m file

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
    return NO;
}
like image 21
Cyprian Avatar answered Nov 10 '22 19:11

Cyprian