开发者

Problem with UILabel

开发者 https://www.devze.com 2023-02-17 18:54 出处:网络
I have a problem with a UILabel. Imagine I have a string @\"I am a software engineer and working on iphone Apps\".

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开发者_如何学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 heightshould 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号