Adnan Ahmad
Adnan Ahmad

Reputation: 447

Problem with UILabel

I have a problem with a UILabel.

Imagine I have a string @"I am a software engineer and working on iphone Apps". I want to show this string in 3 lines in UILabel am doing these steps

  1. Make a UILabel IBOutlet in a custom cell and name it courseHeadingLabel;

  2. In table View I write the code:

cell.courseHeadingLabel.numberOfLines=0;

cell.courseHeadingLabel.text=couseHeading;

cell.lineBreakMode = UILineBreakModeCharacterWrap;

However this doesn't appear to work.

Upvotes: 0

Views: 212

Answers (2)

Clad
Clad

Reputation: 1561

You did the right thing setting numberOfLines to 0, it will use as many lines as needed (but if 3 lines is a strict maximum, set this to 3 instead).

However, for the wrapping to occur, you need to give your label a correct width and height: if the height is not big enough, you won't see the other lines under the first one.

Change the height by setting the frame attribute of courseHeadingLabel (setting the height to three times the current heightshould do it).

Something like this:

CGRect r = cell.courseHeadingLabel.frame;
r.size.height *= 3;
cell.courseHeadingLabel.frame = r;

Upvotes: 1

Saurabh
Saurabh

Reputation: 22873

set numberOfLines to 3 and also increase the height to 3 times

Upvotes: 0

Related Questions