Label in two rows

橙三吉。 提交于 2020-01-06 09:02:56

问题


I have a label in 2 lines in my app but the last word in the first line breaks in two rows. For example if last word is 'home' I have h in the first line and ome in the second. How can I fix that?

UPDATE:

Put over IB and in code word wrap but without success.

Code part:

...
cell.leftArticleTitleLabel.lineBreakMode = NSLineBreakByWordWrapping;

        [cell.leftArticleTitleLabel setLineBreakMode:TRUE];
        cell.leftArticleTitleView.frame = CGRectMake(cell.leftArticleTitleView.frame.origin.x, 40, 159, 40);
        cell.leftArticleTitleLabel.frame = CGRectMake(cell.leftArticleTitleLabel.frame.origin.x, cell.leftArticleTitleLabel.frame.origin.y, 149, 40);
...

UPDATE 2: Solved

I should put "setLineBreakMode:TRUE" first :-)

...
[cell.leftArticleTitleLabel setLineBreakMode:TRUE];
cell.leftArticleTitleLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.leftArticleTitleView.frame = CGRectMake(cell.leftArticleTitleView.frame.origin.x, 40, 159, 40);
cell.leftArticleTitleLabel.frame = CGRectMake(cell.leftArticleTitleLabel.frame.origin.x, cell.leftArticleTitleLabel.frame.origin.y, 149, 40);
 ...

回答1:


change the line break mode of the label to word wrapping.

graphically:

in code:

label.lineBreakMode = NSLineBreakByWordWrapping;


来源:https://stackoverflow.com/questions/13002134/label-in-two-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!