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
Make a UILabel IBOutlet in a custom cell and name it courseHeadingLabel;
In table View I write the code:
cell.courseHeadingLabel.numberOfLines=0;
cell.courseHeadingLabel.text=couseHeading;
cell.lineBreakMode = UILineBreakModeCharacterWrap;
However this doesn't开发者_如何学Go appear to work.
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 height
should do it).
Something like this:
CGRect r = cell.courseHeadingLabel.frame;
r.size.height *= 3;
cell.courseHeadingLabel.frame = r;
set numberOfLines to 3 and also increase the height to 3 times
精彩评论