Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gwelmarten

macrumors 6502
Original poster
Jan 17, 2011
476
0
England!
Hi
I've got a UILabelView that takes up a large amount of space (and it has to do this).
However, I want the text within it to stay within a small area within it. I've had a look around, and I see there is a method fro containing the area text can occupy in a text view - is there something similar for UILabelView? So I can keep text within a CGRect of the label view?
Thanks for your help,
Sam
 
Why does it have to take up a large amount of space?

Because of an animation I'm running on it. I have thought about resizing it, but no-one in my team can think of a way of then handling the animation.
So is there a way of handling a constraint? I couldn't see one in the class reference, so I presume no.

----------

Just realised I was looking in the Mac class reference - in the iOS one, I saw:
textRectForBounds:limitedToNumberOfLines:
I think something like this will work, so I'm going to try. Any views on if it will?
 
Because of an animation I'm running on it. I have thought about resizing it, but no-one in my team can think of a way of then handling the animation.

What kind of animation? Have you considered animating a UIView and having the UILabel (there is no UILabelView, by the way) as a subview?
 
No idea! Give it a try and report back.

Hmm...no luck. To create the UILabelView, I've got:
Code:
    question = [[UILabel alloc] init];
    question.frame = CGRectMake(0, 0, 480, 300);
    question.textAlignment = UITextAlignmentCenter;
    question.text = @"Loading...";
    question.lineBreakMode = UILineBreakModeWordWrap;
    question.numberOfLines = 4; //Or whatever you want
    question.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"x019xm2.png"]];
    [question drawTextInRect:CGRectMake(100, 100, 50, 50)];
    [self.view addSubview:question];
Now it hasn't worked, I quickly googled drawTextInRect and others seem to have similar code. Is the CGRect still based on the screen size - not the size of the UILabelView?

Sam

----------

What kind of animation? Have you considered animating a UIView and having the UILabel (there is no UILabelView, by the way) as a subview?

Hi Dejo
Yes, we did, and we tried it. And no, it didn't work for what we are trying to do.
Sam

----------

Oh...just read the rest of the class reference, and that method is only for subclassing.
So it won't work in the way I was trying.
I'll have to try and find another way. If I do, I'll post it back here for your interest.
Sam
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.